summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2010-11-11 20:52:24 +0000
committerdim <dim@FreeBSD.org>2010-11-11 20:52:24 +0000
commit37e50857240f22fdc2beb83a5bf670c44a94212d (patch)
tree9a6496b320a182a536b4a33b916ab30b48840f06
parentcfbe0682af24afabd3a5a9652758cf3ef046843b (diff)
parent56b80da7cac820e4575a4eca93a1c13c386ccec5 (diff)
downloadFreeBSD-src-37e50857240f22fdc2beb83a5bf670c44a94212d.zip
FreeBSD-src-37e50857240f22fdc2beb83a5bf670c44a94212d.tar.gz
Sync: merge r214895 through r215140 from ^/head.
-rw-r--r--Makefile2
-rw-r--r--Makefile.inc19
-rw-r--r--ObsoleteFiles.inc4
-rw-r--r--bin/test/TEST.README24
-rw-r--r--bin/test/TEST.csh152
-rw-r--r--contrib/binutils/bfd/opncls.c2
-rw-r--r--contrib/bzip2/CHANGES12
-rw-r--r--contrib/bzip2/LICENSE4
-rw-r--r--contrib/bzip2/Makefile6
-rw-r--r--contrib/bzip2/Makefile-libbz2_so14
-rw-r--r--contrib/bzip2/README9
-rw-r--r--contrib/bzip2/README.COMPILATION.PROBLEMS6
-rw-r--r--contrib/bzip2/blocksort.c4
-rw-r--r--contrib/bzip2/bzip2.16
-rw-r--r--contrib/bzip2/bzip2.c8
-rw-r--r--contrib/bzip2/bzip2recover.c6
-rw-r--r--contrib/bzip2/bzlib.c4
-rw-r--r--contrib/bzip2/bzlib.h4
-rw-r--r--contrib/bzip2/bzlib_private.h6
-rw-r--r--contrib/bzip2/compress.c4
-rw-r--r--contrib/bzip2/crctable.c4
-rw-r--r--contrib/bzip2/decompress.c17
-rw-r--r--contrib/bzip2/huffman.c4
-rw-r--r--contrib/bzip2/randtable.c4
-rw-r--r--contrib/bzip2/spewG.c4
-rw-r--r--contrib/bzip2/unzcrash.c4
-rw-r--r--contrib/compiler-rt/BlocksRuntime/Block.h59
-rw-r--r--contrib/compiler-rt/BlocksRuntime/Block_private.h179
-rw-r--r--contrib/compiler-rt/BlocksRuntime/data.c41
-rw-r--r--contrib/compiler-rt/BlocksRuntime/runtime.c700
-rw-r--r--contrib/compiler-rt/CREDITS.TXT21
-rw-r--r--contrib/compiler-rt/LICENSE.TXT63
-rw-r--r--contrib/compiler-rt/README.txt330
-rw-r--r--contrib/compiler-rt/lib/absvdi2.c30
-rw-r--r--contrib/compiler-rt/lib/absvsi2.c30
-rw-r--r--contrib/compiler-rt/lib/absvti2.c34
-rw-r--r--contrib/compiler-rt/lib/adddf3.c154
-rw-r--r--contrib/compiler-rt/lib/addsf3.c164
-rw-r--r--contrib/compiler-rt/lib/addvdi3.c37
-rw-r--r--contrib/compiler-rt/lib/addvsi3.c37
-rw-r--r--contrib/compiler-rt/lib/addvti3.c41
-rw-r--r--contrib/compiler-rt/lib/apple_versioning.c150
-rw-r--r--contrib/compiler-rt/lib/arm/adddf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/addsf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/bswapdi2.S36
-rw-r--r--contrib/compiler-rt/lib/arm/bswapsi2.S28
-rw-r--r--contrib/compiler-rt/lib/arm/comparesf2.S130
-rw-r--r--contrib/compiler-rt/lib/arm/divdf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/divsf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/eqdf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/eqsf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/extendsfdf2vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/fixdfsivfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/fixsfsivfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/fixunsdfsivfp.S25
-rw-r--r--contrib/compiler-rt/lib/arm/fixunssfsivfp.S25
-rw-r--r--contrib/compiler-rt/lib/arm/floatsidfvfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/floatsisfvfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/floatunssidfvfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/floatunssisfvfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/gedf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/gesf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/gtdf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/gtsf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/ledf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/lesf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/ltdf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/ltsf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/modsi3.S36
-rw-r--r--contrib/compiler-rt/lib/arm/muldf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/mulsf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/nedf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/negdf2vfp.S21
-rw-r--r--contrib/compiler-rt/lib/arm/negsf2vfp.S21
-rw-r--r--contrib/compiler-rt/lib/arm/nesf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/arm/restore_vfp_d8_d15_regs.S37
-rw-r--r--contrib/compiler-rt/lib/arm/save_vfp_d8_d15_regs.S35
-rw-r--r--contrib/compiler-rt/lib/arm/subdf3vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/subsf3vfp.S25
-rw-r--r--contrib/compiler-rt/lib/arm/switch16.S44
-rw-r--r--contrib/compiler-rt/lib/arm/switch32.S46
-rw-r--r--contrib/compiler-rt/lib/arm/switch8.S43
-rw-r--r--contrib/compiler-rt/lib/arm/switchu8.S43
-rw-r--r--contrib/compiler-rt/lib/arm/sync_synchronize.S34
-rw-r--r--contrib/compiler-rt/lib/arm/truncdfsf2vfp.S24
-rw-r--r--contrib/compiler-rt/lib/arm/unorddf2vfp.S27
-rw-r--r--contrib/compiler-rt/lib/arm/unordsf2vfp.S28
-rw-r--r--contrib/compiler-rt/lib/ashldi3.c41
-rw-r--r--contrib/compiler-rt/lib/ashlti3.c45
-rw-r--r--contrib/compiler-rt/lib/ashrdi3.c42
-rw-r--r--contrib/compiler-rt/lib/ashrti3.c46
-rw-r--r--contrib/compiler-rt/lib/assembly.h54
-rw-r--r--contrib/compiler-rt/lib/clear_cache.c41
-rw-r--r--contrib/compiler-rt/lib/clzdi2.c29
-rw-r--r--contrib/compiler-rt/lib/clzsi2.c53
-rw-r--r--contrib/compiler-rt/lib/clzti2.c33
-rw-r--r--contrib/compiler-rt/lib/cmpdi2.c38
-rw-r--r--contrib/compiler-rt/lib/cmpti2.c42
-rw-r--r--contrib/compiler-rt/lib/comparedf2.c132
-rw-r--r--contrib/compiler-rt/lib/comparesf2.c131
-rw-r--r--contrib/compiler-rt/lib/ctzdi2.c29
-rw-r--r--contrib/compiler-rt/lib/ctzsi2.c57
-rw-r--r--contrib/compiler-rt/lib/ctzti2.c33
-rw-r--r--contrib/compiler-rt/lib/divdc3.c59
-rw-r--r--contrib/compiler-rt/lib/divdf3.c182
-rw-r--r--contrib/compiler-rt/lib/divdi3.c31
-rw-r--r--contrib/compiler-rt/lib/divsc3.c59
-rw-r--r--contrib/compiler-rt/lib/divsf3.c166
-rw-r--r--contrib/compiler-rt/lib/divsi3.c31
-rw-r--r--contrib/compiler-rt/lib/divti3.c35
-rw-r--r--contrib/compiler-rt/lib/divxc3.c62
-rw-r--r--contrib/compiler-rt/lib/enable_execute_stack.c58
-rw-r--r--contrib/compiler-rt/lib/endianness.h94
-rw-r--r--contrib/compiler-rt/lib/eprintf.c33
-rw-r--r--contrib/compiler-rt/lib/extendsfdf2.c136
-rw-r--r--contrib/compiler-rt/lib/ffsdi2.c33
-rw-r--r--contrib/compiler-rt/lib/ffsti2.c37
-rw-r--r--contrib/compiler-rt/lib/fixdfdi.c43
-rw-r--r--contrib/compiler-rt/lib/fixdfsi.c45
-rw-r--r--contrib/compiler-rt/lib/fixdfti.c45
-rw-r--r--contrib/compiler-rt/lib/fixsfdi.c41
-rw-r--r--contrib/compiler-rt/lib/fixsfsi.c45
-rw-r--r--contrib/compiler-rt/lib/fixsfti.c45
-rw-r--r--contrib/compiler-rt/lib/fixunsdfdi.c45
-rw-r--r--contrib/compiler-rt/lib/fixunsdfsi.c42
-rw-r--r--contrib/compiler-rt/lib/fixunsdfti.c47
-rw-r--r--contrib/compiler-rt/lib/fixunssfdi.c43
-rw-r--r--contrib/compiler-rt/lib/fixunssfsi.c43
-rw-r--r--contrib/compiler-rt/lib/fixunssfti.c47
-rw-r--r--contrib/compiler-rt/lib/fixunsxfdi.c44
-rw-r--r--contrib/compiler-rt/lib/fixunsxfsi.c44
-rw-r--r--contrib/compiler-rt/lib/fixunsxfti.c49
-rw-r--r--contrib/compiler-rt/lib/fixxfdi.c44
-rw-r--r--contrib/compiler-rt/lib/fixxfti.c47
-rw-r--r--contrib/compiler-rt/lib/floatdidf.c107
-rw-r--r--contrib/compiler-rt/lib/floatdisf.c79
-rw-r--r--contrib/compiler-rt/lib/floatdixf.c46
-rw-r--r--contrib/compiler-rt/lib/floatsidf.c48
-rw-r--r--contrib/compiler-rt/lib/floatsisf.c54
-rw-r--r--contrib/compiler-rt/lib/floattidf.c86
-rw-r--r--contrib/compiler-rt/lib/floattisf.c85
-rw-r--r--contrib/compiler-rt/lib/floattixf.c87
-rw-r--r--contrib/compiler-rt/lib/floatundidf.c107
-rw-r--r--contrib/compiler-rt/lib/floatundisf.c76
-rw-r--r--contrib/compiler-rt/lib/floatundixf.c42
-rw-r--r--contrib/compiler-rt/lib/floatunsidf.c37
-rw-r--r--contrib/compiler-rt/lib/floatunsisf.c45
-rw-r--r--contrib/compiler-rt/lib/floatuntidf.c83
-rw-r--r--contrib/compiler-rt/lib/floatuntisf.c82
-rw-r--r--contrib/compiler-rt/lib/floatuntixf.c84
-rw-r--r--contrib/compiler-rt/lib/fp_lib.h143
-rw-r--r--contrib/compiler-rt/lib/gcc_personality_v0.c251
-rw-r--r--contrib/compiler-rt/lib/i386/ashldi3.S56
-rw-r--r--contrib/compiler-rt/lib/i386/ashrdi3.S67
-rw-r--r--contrib/compiler-rt/lib/i386/divdi3.S161
-rw-r--r--contrib/compiler-rt/lib/i386/floatdidf.S35
-rw-r--r--contrib/compiler-rt/lib/i386/floatdisf.S31
-rw-r--r--contrib/compiler-rt/lib/i386/floatdixf.S29
-rw-r--r--contrib/compiler-rt/lib/i386/floatundidf.S46
-rw-r--r--contrib/compiler-rt/lib/i386/floatundisf.S99
-rw-r--r--contrib/compiler-rt/lib/i386/floatundixf.S37
-rw-r--r--contrib/compiler-rt/lib/i386/lshrdi3.S57
-rw-r--r--contrib/compiler-rt/lib/i386/moddi3.S166
-rw-r--r--contrib/compiler-rt/lib/i386/muldi3.S29
-rw-r--r--contrib/compiler-rt/lib/i386/udivdi3.S114
-rw-r--r--contrib/compiler-rt/lib/i386/umoddi3.S125
-rw-r--r--contrib/compiler-rt/lib/int_lib.h155
-rw-r--r--contrib/compiler-rt/lib/lshrdi3.c41
-rw-r--r--contrib/compiler-rt/lib/lshrti3.c45
-rw-r--r--contrib/compiler-rt/lib/moddi3.c32
-rw-r--r--contrib/compiler-rt/lib/modsi3.c23
-rw-r--r--contrib/compiler-rt/lib/modti3.c36
-rw-r--r--contrib/compiler-rt/lib/muldc3.c74
-rw-r--r--contrib/compiler-rt/lib/muldf3.c119
-rw-r--r--contrib/compiler-rt/lib/muldi3.c54
-rw-r--r--contrib/compiler-rt/lib/mulsc3.c74
-rw-r--r--contrib/compiler-rt/lib/mulsf3.c109
-rw-r--r--contrib/compiler-rt/lib/multi3.c58
-rw-r--r--contrib/compiler-rt/lib/mulvdi3.c57
-rw-r--r--contrib/compiler-rt/lib/mulvsi3.c57
-rw-r--r--contrib/compiler-rt/lib/mulvti3.c61
-rw-r--r--contrib/compiler-rt/lib/mulxc3.c78
-rw-r--r--contrib/compiler-rt/lib/negdf2.c19
-rw-r--r--contrib/compiler-rt/lib/negdi2.c26
-rw-r--r--contrib/compiler-rt/lib/negsf2.c19
-rw-r--r--contrib/compiler-rt/lib/negti2.c30
-rw-r--r--contrib/compiler-rt/lib/negvdi2.c29
-rw-r--r--contrib/compiler-rt/lib/negvsi2.c29
-rw-r--r--contrib/compiler-rt/lib/negvti2.c33
-rw-r--r--contrib/compiler-rt/lib/paritydi2.c27
-rw-r--r--contrib/compiler-rt/lib/paritysi2.c27
-rw-r--r--contrib/compiler-rt/lib/parityti2.c31
-rw-r--r--contrib/compiler-rt/lib/popcountdi2.c36
-rw-r--r--contrib/compiler-rt/lib/popcountsi2.c33
-rw-r--r--contrib/compiler-rt/lib/popcountti2.c44
-rw-r--r--contrib/compiler-rt/lib/powidf2.c34
-rw-r--r--contrib/compiler-rt/lib/powisf2.c34
-rw-r--r--contrib/compiler-rt/lib/powitf2.c38
-rw-r--r--contrib/compiler-rt/lib/powixf2.c38
-rw-r--r--contrib/compiler-rt/lib/ppc/DD.h46
-rw-r--r--contrib/compiler-rt/lib/ppc/divtc3.c93
-rw-r--r--contrib/compiler-rt/lib/ppc/fixtfdi.c104
-rw-r--r--contrib/compiler-rt/lib/ppc/fixunstfdi.c60
-rw-r--r--contrib/compiler-rt/lib/ppc/floatditf.c37
-rw-r--r--contrib/compiler-rt/lib/ppc/floatunditf.c42
-rw-r--r--contrib/compiler-rt/lib/ppc/gcc_qadd.c76
-rw-r--r--contrib/compiler-rt/lib/ppc/gcc_qdiv.c55
-rw-r--r--contrib/compiler-rt/lib/ppc/gcc_qmul.c53
-rw-r--r--contrib/compiler-rt/lib/ppc/gcc_qsub.c76
-rw-r--r--contrib/compiler-rt/lib/ppc/multc3.c97
-rw-r--r--contrib/compiler-rt/lib/ppc/restFP.S43
-rw-r--r--contrib/compiler-rt/lib/ppc/saveFP.S40
-rw-r--r--contrib/compiler-rt/lib/subvdi3.c37
-rw-r--r--contrib/compiler-rt/lib/subvsi3.c37
-rw-r--r--contrib/compiler-rt/lib/subvti3.c41
-rw-r--r--contrib/compiler-rt/lib/trampoline_setup.c50
-rw-r--r--contrib/compiler-rt/lib/truncdfsf2.c167
-rw-r--r--contrib/compiler-rt/lib/ucmpdi2.c38
-rw-r--r--contrib/compiler-rt/lib/ucmpti2.c42
-rw-r--r--contrib/compiler-rt/lib/udivdi3.c25
-rw-r--r--contrib/compiler-rt/lib/udivmoddi4.c251
-rw-r--r--contrib/compiler-rt/lib/udivmodti4.c256
-rw-r--r--contrib/compiler-rt/lib/udivsi3.c63
-rw-r--r--contrib/compiler-rt/lib/udivti3.c29
-rw-r--r--contrib/compiler-rt/lib/umoddi3.c27
-rw-r--r--contrib/compiler-rt/lib/umodsi3.c25
-rw-r--r--contrib/compiler-rt/lib/umodti3.c31
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatdidf.c16
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatdisf.c14
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatdixf.c16
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatundidf.S43
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatundisf.S33
-rw-r--r--contrib/compiler-rt/lib/x86_64/floatundixf.S62
-rw-r--r--contrib/gdb/gdb/mips-tdep.c17
-rw-r--r--contrib/gdb/gdb/mips-tdep.h2
-rw-r--r--contrib/gdb/gdb/mipsfbsd-tdep.h4
-rw-r--r--crypto/openssh/ChangeLog519
-rw-r--r--crypto/openssh/PROTOCOL.certkeys106
-rw-r--r--crypto/openssh/PROTOCOL.mux13
-rw-r--r--crypto/openssh/README4
-rw-r--r--crypto/openssh/auth-options.c328
-rw-r--r--crypto/openssh/auth-options.h5
-rw-r--r--crypto/openssh/auth-rsa.c9
-rw-r--r--crypto/openssh/auth.c48
-rw-r--r--crypto/openssh/auth.h4
-rw-r--r--crypto/openssh/auth1.c4
-rw-r--r--crypto/openssh/auth2-hostbased.c31
-rw-r--r--crypto/openssh/auth2-none.c4
-rw-r--r--crypto/openssh/auth2-pubkey.c145
-rw-r--r--crypto/openssh/authfd.c6
-rw-r--r--crypto/openssh/authfile.c62
-rw-r--r--crypto/openssh/authfile.h4
-rw-r--r--crypto/openssh/bufaux.c8
-rw-r--r--crypto/openssh/channels.c99
-rw-r--r--crypto/openssh/channels.h8
-rw-r--r--crypto/openssh/clientloop.c89
-rw-r--r--crypto/openssh/clientloop.h5
-rw-r--r--crypto/openssh/config.h3
-rw-r--r--crypto/openssh/config.h.in3
-rw-r--r--crypto/openssh/jpake.c4
-rw-r--r--crypto/openssh/key.c182
-rw-r--r--crypto/openssh/key.h11
-rw-r--r--crypto/openssh/loginrec.h2
-rw-r--r--crypto/openssh/misc.c19
-rw-r--r--crypto/openssh/misc.h3
-rw-r--r--crypto/openssh/monitor.c20
-rw-r--r--crypto/openssh/mux.c181
-rw-r--r--crypto/openssh/myproposal.h11
-rw-r--r--crypto/openssh/openbsd-compat/openbsd-compat.h7
-rw-r--r--crypto/openssh/openbsd-compat/openssl-compat.h13
-rw-r--r--crypto/openssh/openbsd-compat/port-tun.c8
-rw-r--r--crypto/openssh/openbsd-compat/port-uw.c2
-rw-r--r--crypto/openssh/openbsd-compat/strptime.c401
-rw-r--r--crypto/openssh/packet.c4
-rw-r--r--crypto/openssh/readconf.c71
-rw-r--r--crypto/openssh/readconf.h10
-rw-r--r--crypto/openssh/scp.c20
-rw-r--r--crypto/openssh/servconf.c31
-rw-r--r--crypto/openssh/servconf.h3
-rw-r--r--crypto/openssh/session.c46
-rw-r--r--crypto/openssh/sftp-client.c7
-rw-r--r--crypto/openssh/sftp.c6
-rw-r--r--crypto/openssh/ssh-add.c50
-rw-r--r--crypto/openssh/ssh-agent.c5
-rw-r--r--crypto/openssh/ssh-dss.c12
-rw-r--r--crypto/openssh/ssh-keygen.189
-rw-r--r--crypto/openssh/ssh-keygen.c759
-rw-r--r--crypto/openssh/ssh-keyscan.c165
-rw-r--r--crypto/openssh/ssh-keysign.87
-rw-r--r--crypto/openssh/ssh-keysign.c4
-rw-r--r--crypto/openssh/ssh-pkcs11-helper.025
-rw-r--r--crypto/openssh/ssh-pkcs11.c53
-rw-r--r--crypto/openssh/ssh-rsa.c21
-rw-r--r--crypto/openssh/ssh.176
-rw-r--r--crypto/openssh/ssh.c199
-rw-r--r--crypto/openssh/ssh.h5
-rw-r--r--crypto/openssh/ssh_config2
-rw-r--r--crypto/openssh/ssh_config.577
-rw-r--r--crypto/openssh/sshconnect.c14
-rw-r--r--crypto/openssh/sshconnect2.c12
-rw-r--r--crypto/openssh/sshd.818
-rw-r--r--crypto/openssh/sshd.c15
-rw-r--r--crypto/openssh/sshd_config2
-rw-r--r--crypto/openssh/sshd_config.555
-rw-r--r--crypto/openssh/version.h6
-rw-r--r--etc/periodic/security/Makefile5
-rw-r--r--gnu/lib/libgcc/Makefile37
-rw-r--r--gnu/usr.bin/binutils/Makefile.inc031
-rw-r--r--gnu/usr.bin/binutils/as/Makefile6
-rw-r--r--gnu/usr.bin/binutils/ld/Makefile.arm2
-rw-r--r--gnu/usr.bin/binutils/ld/Makefile.mips4
-rw-r--r--gnu/usr.bin/binutils/libbfd/Makefile.arm4
-rw-r--r--gnu/usr.bin/binutils/libbfd/Makefile.mips6
-rw-r--r--gnu/usr.bin/cc/Makefile.inc10
-rw-r--r--gnu/usr.bin/cc/Makefile.tgt19
-rw-r--r--gnu/usr.bin/cc/cc_int/Makefile4
-rw-r--r--gnu/usr.bin/cc/cc_tools/Makefile22
-rw-r--r--gnu/usr.bin/gdb/Makefile.inc14
-rw-r--r--gnu/usr.bin/gdb/arch/mips/Makefile2
-rw-r--r--gnu/usr.bin/gdb/arch/mips/init.c5
-rw-r--r--gnu/usr.bin/gdb/kgdb/Makefile2
-rw-r--r--gnu/usr.bin/gdb/kgdb/trgt_mips.c41
-rw-r--r--gnu/usr.bin/gdb/libgdb/Makefile10
-rw-r--r--lib/Makefile2
-rw-r--r--lib/libarchive/archive_read_support_format_zip.c53
-rw-r--r--lib/libarchive/test/test_compat_zip.c33
-rw-r--r--lib/libarchive/test/test_compat_zip_2.zip.uu10
-rw-r--r--lib/libblocksruntime/Makefile13
-rw-r--r--lib/libblocksruntime/config.h14
-rw-r--r--lib/libcompiler_rt/Makefile157
-rw-r--r--lib/libkvm/Makefile2
-rw-r--r--lib/libkvm/kvm_minidump_amd64.c108
-rw-r--r--lib/libkvm/kvm_minidump_mips.c275
-rw-r--r--lib/libkvm/kvm_mips.c49
-rw-r--r--lib/libkvm/kvm_private.h3
-rw-r--r--libexec/tftpd/tftp-utils.c2
-rw-r--r--release/sparc64/boot_crunch.conf5
-rw-r--r--share/man/man4/Makefile1
-rw-r--r--share/man/man4/ada.42
-rw-r--r--share/man/man4/aibs.46
-rw-r--r--share/man/man4/bge.410
-rw-r--r--share/man/man4/u3g.425
-rw-r--r--share/man/man4/usb_quirk.4196
-rw-r--r--share/man/man9/Makefile1
-rw-r--r--share/man/man9/taskqueue.927
-rw-r--r--share/misc/committers-src.dot2
-rw-r--r--share/mk/bsd.cpu.mk8
-rw-r--r--share/mk/bsd.endian.mk8
-rw-r--r--sys/amd64/acpica/acpi_machdep.c456
-rw-r--r--sys/amd64/acpica/madt.c573
-rw-r--r--sys/amd64/amd64/amd64_mem.c4
-rw-r--r--sys/amd64/amd64/minidump_machdep.c159
-rw-r--r--sys/amd64/amd64/mp_machdep.c4
-rw-r--r--sys/amd64/include/apm_bios.h264
-rw-r--r--sys/amd64/include/minidump.h4
-rw-r--r--sys/amd64/include/mutex.h35
-rw-r--r--sys/arm/conf/AVILA4
-rw-r--r--sys/arm/conf/AVILA.hints3
-rw-r--r--sys/arm/conf/BWCT.hints4
-rw-r--r--sys/arm/include/cpuconf.h13
-rw-r--r--sys/arm/include/mutex.h32
-rw-r--r--sys/arm/xscale/ixp425/avila_gpio.c380
-rw-r--r--sys/arm/xscale/ixp425/files.avila1
-rw-r--r--sys/arm/xscale/ixp425/ixp425_qmgr.c4
-rw-r--r--sys/arm/xscale/ixp425/ixp425reg.h2
-rw-r--r--sys/boot/arm/ixp425/boot2/ixp425_board.c4
-rw-r--r--sys/boot/common/loader.86
-rw-r--r--sys/boot/fdt/dts/mpc8555cds.dts2
-rw-r--r--sys/boot/forth/beastie.4th9
-rw-r--r--sys/boot/i386/libi386/biosacpi.c7
-rw-r--r--sys/boot/i386/libi386/i386_module.c18
-rw-r--r--sys/boot/i386/loader/help.i38618
-rw-r--r--sys/cam/cam_periph.c5
-rw-r--r--sys/compat/linprocfs/linprocfs.c9
-rw-r--r--sys/compat/ndis/subr_ntoskrnl.c9
-rw-r--r--sys/conf/Makefile.mips17
-rw-r--r--sys/conf/files.amd645
-rw-r--r--sys/conf/files.i3865
-rw-r--r--sys/conf/files.mips1
-rw-r--r--sys/contrib/octeon-sdk/cvmx-app-init.h6
-rw-r--r--sys/contrib/octeon-sdk/cvmx-helper-board.c16
-rw-r--r--sys/contrib/octeon-sdk/cvmx-helper.c2
-rw-r--r--sys/dev/acpica/acpi.c2
-rw-r--r--sys/dev/acpica/acpivar.h3
-rw-r--r--sys/dev/ahci/ahci.c30
-rw-r--r--sys/dev/ata/ata-all.c9
-rw-r--r--sys/dev/ata/ata-disk.c8
-rw-r--r--sys/dev/ata/ata-lowlevel.c21
-rw-r--r--sys/dev/drm/r300_reg.h12
-rw-r--r--sys/dev/gpio/gpioled.c3
-rw-r--r--sys/dev/iicbus/iiconf.c34
-rw-r--r--sys/dev/isp/isp_freebsd.c14
-rw-r--r--sys/dev/ixgbe/ixgbe.c10
-rw-r--r--sys/dev/mii/brgphy.c1
-rw-r--r--sys/dev/mii/miidevs1
-rw-r--r--sys/dev/msk/if_msk.c18
-rw-r--r--sys/dev/nfe/if_nfe.c229
-rw-r--r--sys/dev/nfe/if_nfereg.h1
-rw-r--r--sys/dev/nfe/if_nfevar.h1
-rw-r--r--sys/dev/ofw/ofw_fdt.c16
-rw-r--r--sys/dev/ofw/openfirm.c80
-rw-r--r--sys/dev/pccard/pccardvar.h6
-rw-r--r--sys/dev/re/if_re.c34
-rw-r--r--sys/dev/siis/siis.c11
-rw-r--r--sys/dev/sk/if_sk.c44
-rw-r--r--sys/dev/sound/sbus/cs4231.c4
-rw-r--r--sys/dev/syscons/schistory.c6
-rw-r--r--sys/dev/uart/uart_subr.c4
-rw-r--r--sys/dev/usb/quirk/usb_quirk.c10
-rw-r--r--sys/dev/usb/quirk/usb_quirk.h69
-rw-r--r--sys/dev/usb/serial/u3g.c38
-rw-r--r--sys/dev/usb/serial/usb_serial.c7
-rw-r--r--sys/dev/wb/if_wb.c2
-rw-r--r--sys/fs/nwfs/nwfs_vnops.c2
-rw-r--r--sys/geom/part/g_part.c20
-rw-r--r--sys/i386/acpica/OsdEnvironment.c71
-rw-r--r--sys/i386/acpica/acpi_machdep.c461
-rw-r--r--sys/i386/bios/apm.c17
-rw-r--r--sys/i386/i386/machdep.c97
-rw-r--r--sys/i386/i386/mp_machdep.c19
-rw-r--r--sys/i386/i386/pmap.c15
-rw-r--r--sys/i386/include/apm_bios.h264
-rw-r--r--sys/i386/include/mptable.h146
-rw-r--r--sys/i386/include/mutex.h66
-rw-r--r--sys/i386/xen/mptable.c4
-rw-r--r--sys/ia64/acpica/OsdEnvironment.c28
-rw-r--r--sys/ia64/ia64/db_machdep.c1
-rw-r--r--sys/ia64/ia64/genassym.c1
-rw-r--r--sys/ia64/ia64/machdep.c1
-rw-r--r--sys/ia64/include/mutex.h70
-rw-r--r--sys/kern/kern_clocksource.c46
-rw-r--r--sys/kern/kern_conf.c3
-rw-r--r--sys/kern/kern_mutex.c22
-rw-r--r--sys/kern/kern_proc.c22
-rw-r--r--sys/kern/link_elf.c1912
-rw-r--r--sys/kern/sched_ule.c4
-rw-r--r--sys/kern/subr_lock.c2
-rw-r--r--sys/kern/subr_taskqueue.c50
-rw-r--r--sys/mips/conf/SWARM2
-rw-r--r--sys/mips/conf/SWARM642
-rw-r--r--sys/mips/conf/SWARM64_SMP2
-rw-r--r--sys/mips/conf/SWARM_COMMON60
-rw-r--r--sys/mips/conf/SWARM_SMP2
-rw-r--r--sys/mips/conf/XLR4
-rw-r--r--sys/mips/conf/XLR644
-rw-r--r--sys/mips/conf/XLRN324
-rw-r--r--sys/mips/include/cpuregs.h3
-rw-r--r--sys/mips/include/md_var.h5
-rw-r--r--sys/mips/include/mutex.h2
-rw-r--r--sys/mips/include/pmap.h2
-rw-r--r--sys/mips/mips/dump_machdep.c369
-rw-r--r--sys/mips/mips/gdb_machdep.c43
-rw-r--r--sys/mips/mips/machdep.c8
-rw-r--r--sys/mips/mips/minidump_machdep.c340
-rw-r--r--sys/mips/mips/vm_machdep.c8
-rw-r--r--sys/modules/acpi/Makefile6
-rw-r--r--sys/modules/acpi/acpi/Makefile5
-rw-r--r--sys/net/vnet.h2
-rw-r--r--sys/netinet/in_pcb.c9
-rw-r--r--sys/netinet/sctp.h14
-rw-r--r--sys/netinet/sctp_indata.c4
-rw-r--r--sys/netinet/sctp_input.c4
-rw-r--r--sys/netinet/sctp_os_bsd.h4
-rw-r--r--sys/netinet/sctp_output.c17
-rw-r--r--sys/netinet/sctp_pcb.c85
-rw-r--r--sys/netinet/sctp_timer.c101
-rw-r--r--sys/netinet/sctp_timer.h3
-rw-r--r--sys/netinet/sctp_uio.h18
-rw-r--r--sys/netinet/sctp_usrreq.c2
-rw-r--r--sys/netinet/sctputil.c87
-rw-r--r--sys/netinet/sctputil.h3
-rw-r--r--sys/pc98/include/apm_bios.h2
-rw-r--r--sys/pc98/include/mptable.h6
-rw-r--r--sys/pc98/include/mutex.h6
-rw-r--r--sys/pci/if_rlreg.h986
-rw-r--r--sys/powerpc/aim/clock.c2
-rw-r--r--sys/powerpc/aim/machdep.c9
-rw-r--r--sys/powerpc/aim/mmu_oea64.c8
-rw-r--r--sys/powerpc/aim/nexus.c6
-rw-r--r--sys/powerpc/aim/ofw_machdep.c8
-rw-r--r--sys/powerpc/aim/trap_subr32.S201
-rw-r--r--sys/powerpc/booke/clock.c2
-rw-r--r--sys/powerpc/booke/locore.S2
-rw-r--r--sys/powerpc/booke/machdep.c2
-rw-r--r--sys/powerpc/booke/pmap.c2
-rw-r--r--sys/powerpc/booke/trap_subr.S9
-rw-r--r--sys/powerpc/include/mutex.h67
-rw-r--r--sys/powerpc/include/tlb.h5
-rw-r--r--sys/powerpc/powermac/smu.c12
-rw-r--r--sys/powerpc/powerpc/cpu.c4
-rw-r--r--sys/security/mac_portacl/mac_portacl.c2
-rw-r--r--sys/sparc64/include/mutex.h32
-rw-r--r--sys/sparc64/include/vmparam.h11
-rw-r--r--sys/sun4v/include/mutex.h32
-rw-r--r--sys/sun4v/include/pmap.h5
-rw-r--r--sys/sun4v/include/smp.h12
-rw-r--r--sys/sun4v/sun4v/mp_machdep.c2
-rw-r--r--sys/sys/cdefs.h3
-rw-r--r--sys/sys/kernel.h2
-rw-r--r--sys/sys/kerneldump.h1
-rw-r--r--sys/sys/linker_set.h2
-rw-r--r--sys/sys/mutex.h99
-rw-r--r--sys/sys/param.h2
-rw-r--r--sys/sys/pcpu.h6
-rw-r--r--sys/sys/taskqueue.h2
-rw-r--r--sys/ufs/ffs/ffs_inode.c4
-rw-r--r--sys/ufs/ffs/ffs_softdep.c56
-rw-r--r--sys/ufs/ffs/fs.h21
-rw-r--r--sys/ufs/ufs/ufs_vnops.c2
-rw-r--r--sys/vm/vm_map.c3
-rw-r--r--sys/vm/vm_page.c3
-rw-r--r--sys/vm/vm_reserv.c2
-rw-r--r--sys/x86/acpica/OsdEnvironment.c (renamed from sys/amd64/acpica/OsdEnvironment.c)50
-rw-r--r--sys/x86/acpica/acpi_apm.c489
-rw-r--r--sys/x86/acpica/madt.c (renamed from sys/i386/acpica/madt.c)3
-rw-r--r--sys/x86/cpufreq/hwpstate.c3
-rw-r--r--sys/x86/include/apm_bios.h264
-rw-r--r--sys/x86/include/mptable.h (renamed from sys/amd64/include/mptable.h)0
-rw-r--r--sys/x86/x86/local_apic.c29
-rw-r--r--sys/x86/x86/mptable.c4
-rw-r--r--sys/x86/x86/mptable_pci.c2
-rw-r--r--tools/build/mk/OptionalObsoleteFiles.inc1
-rw-r--r--tools/regression/acltools/tools-nfs4.test1
-rw-r--r--tools/regression/bin/Makefile2
-rw-r--r--tools/regression/bin/test/Makefile4
-rw-r--r--tools/regression/bin/test/regress.sh (renamed from bin/test/TEST.sh)38
-rw-r--r--tools/regression/bin/test/regress.t6
-rw-r--r--tools/tools/nanobsd/nanobsd.sh52
-rw-r--r--usr.bin/calendar/calendars/calendar.freebsd53
-rw-r--r--usr.bin/lex/Makefile2
-rw-r--r--usr.bin/lex/initscan.c388
-rw-r--r--usr.bin/objformat/Makefile7
-rw-r--r--usr.bin/objformat/objformat.sh26
-rw-r--r--usr.bin/seq/seq.c6
-rw-r--r--usr.bin/yacc/Makefile2
-rw-r--r--usr.bin/yacc/closure.c25
-rw-r--r--usr.bin/yacc/defs.h8
-rw-r--r--usr.bin/yacc/error.c108
-rw-r--r--usr.bin/yacc/lalr.c72
-rw-r--r--usr.bin/yacc/lr0.c66
-rw-r--r--usr.bin/yacc/main.c47
-rw-r--r--usr.bin/yacc/mkpar.c40
-rw-r--r--usr.bin/yacc/output.c112
-rw-r--r--usr.bin/yacc/reader.c189
-rw-r--r--usr.bin/yacc/skeleton.c3
-rw-r--r--usr.bin/yacc/symtab.c25
-rw-r--r--usr.bin/yacc/verbose.c35
-rw-r--r--usr.bin/yacc/warshall.c8
-rw-r--r--usr.bin/yacc/yacc.16
-rw-r--r--usr.sbin/apmd/apmd.82
-rw-r--r--usr.sbin/config/configvers.h2
-rw-r--r--usr.sbin/freebsd-update/freebsd-update.sh2
-rw-r--r--usr.sbin/makefs/Makefile19
-rw-r--r--usr.sbin/makefs/cd9660.c2154
-rw-r--r--usr.sbin/makefs/cd9660.h364
-rw-r--r--usr.sbin/makefs/cd9660/Makefile.inc9
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_archimedes.c126
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_archimedes.h50
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_conversion.c202
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_debug.c488
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_eltorito.c539
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_eltorito.h164
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_strings.c120
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_write.c518
-rw-r--r--usr.sbin/makefs/cd9660/iso9660_rrip.c836
-rw-r--r--usr.sbin/makefs/cd9660/iso9660_rrip.h290
-rw-r--r--usr.sbin/makefs/compat/Makefile.inc8
-rw-r--r--usr.sbin/makefs/ffs.c236
-rw-r--r--usr.sbin/makefs/ffs.h66
-rw-r--r--usr.sbin/makefs/ffs/Makefile.inc9
-rw-r--r--usr.sbin/makefs/ffs/buf.c6
-rw-r--r--usr.sbin/makefs/ffs/ffs_alloc.c27
-rw-r--r--usr.sbin/makefs/ffs/mkfs.c32
-rw-r--r--usr.sbin/makefs/makefs.8278
-rw-r--r--usr.sbin/makefs/makefs.c36
-rw-r--r--usr.sbin/makefs/makefs.h79
-rw-r--r--usr.sbin/makefs/walk.c237
-rw-r--r--usr.sbin/mptutil/mpt_cam.c18
-rw-r--r--usr.sbin/mptutil/mpt_cmd.c50
-rw-r--r--usr.sbin/mptutil/mpt_config.c215
-rw-r--r--usr.sbin/mptutil/mpt_drive.c38
-rw-r--r--usr.sbin/mptutil/mpt_evt.c10
-rw-r--r--usr.sbin/mptutil/mpt_show.c40
-rw-r--r--usr.sbin/mptutil/mpt_volume.c66
-rwxr-xr-xusr.sbin/pc-sysinstall/backend/functions-disk.sh5
-rw-r--r--usr.sbin/usbconfig/usbconfig.86
586 files changed, 28988 insertions, 7761 deletions
diff --git a/Makefile b/Makefile
index 5edb4da..4209248 100644
--- a/Makefile
+++ b/Makefile
@@ -281,7 +281,7 @@ tinderbox:
# existing system is.
#
.if make(universe) || make(universe_kernels) || make(tinderbox)
-TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
+TARGETS?=amd64 i386 ia64 pc98 powerpc sparc64 sun4v
.if defined(DOING_TINDERBOX)
FAILFILE=tinderbox.failed
diff --git a/Makefile.inc1 b/Makefile.inc1
index a08e4ca..cd29204 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -118,16 +118,16 @@ VERSION+= ${OSRELDATE}
# Guess machine architecture from machine type, and vice versa.
.if !defined(TARGET_ARCH) && defined(TARGET)
-TARGET_ARCH= ${TARGET:S/pc98/i386/:S/sun4v/sparc64/}
+TARGET_ARCH= ${TARGET:S/pc98/i386/:S/sun4v/sparc64/:S/mips/mipsel/}
.elif !defined(TARGET) && defined(TARGET_ARCH) && \
${TARGET_ARCH} != ${MACHINE_ARCH}
-TARGET= ${TARGET_ARCH}
+TARGET= ${TARGET_ARCH:C/mipse[lb]/mips/:C/armeb/arm}
.endif
# Otherwise, default to current machine type and architecture.
TARGET?= ${MACHINE}
TARGET_ARCH?= ${MACHINE_ARCH}
-KNOWN_ARCHES?= amd64 arm i386 i386/pc98 ia64 mips powerpc powerpc64/powerpc sparc64 sparc64/sun4v
+KNOWN_ARCHES?= amd64 arm armeb/arm i386 i386/pc98 ia64 mipsel/mips mipseb/mips powerpc powerpc64/powerpc sparc64 sparc64/sun4v
.if ${TARGET} == ${TARGET_ARCH}
_t= ${TARGET}
.else
@@ -1123,7 +1123,7 @@ libraries:
#
# static libgcc.a prerequisite for shared libc
#
-_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc
+_prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt
# These dependencies are not automatically generated:
#
@@ -1139,6 +1139,7 @@ _startup_libs+= lib/csu/${MACHINE_ARCH}
_startup_libs+= lib/csu/${MACHINE_CPUARCH}
.endif
_startup_libs+= gnu/lib/libgcc
+_startup_libs+= lib/libcompiler_rt
_startup_libs+= lib/libc
gnu/lib/libgcc__L: lib/libc__L
diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index 8ddfc5e..97eea7e 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -14,6 +14,10 @@
# The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last.
#
+# 20101109: headers moved to machine/ to x86/
+.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
+OLD_FILES+=usr/include/machine/mptable.h
+.endif
# 20101101: headers moved to machine/ to x86/
.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386"
OLD_FILES+=usr/include/machine/apicreg.h
diff --git a/bin/test/TEST.README b/bin/test/TEST.README
deleted file mode 100644
index 4fe3524..0000000
--- a/bin/test/TEST.README
+++ /dev/null
@@ -1,24 +0,0 @@
-# $FreeBSD$
-
-OS/shell syntax error failed
---------------------------------------------------------------------
-bash 1.14.5 3 0
-pdksh 5.2.5 7 0
-zsh 2.6-beta17 6 4
-FreeBSD 2.1 /bin/test 8 0
-IRIX 5.3 ksh 3 0
-IRIX 5.3 sh 3 0
-IRIX 5.3 /usr/bin/test 11 3
-SunOS 5.4 ksh 3 0
-SunOS 5.4 sh 3 0
-SunOS 5.4 /usr/ucb/test 3 0
-SunOS 5.5 ksh 0 0
-SunOS 5.5 sh 3 0
-SunOS 5.5 /usr/ucb/test 3 0
-SunOS 4.1.3_U1 sh 3 0
-SunOS 4.1.3_U1 /usr/bin/test 3 0
-ULTRIX 4.2 /bin/test 9 0
-ULTRIX 4.2 ksh 1 0
-ULTRIX 4.2 sh5 4 0
-
-96/06/16
diff --git a/bin/test/TEST.csh b/bin/test/TEST.csh
deleted file mode 100644
index afa1c91..0000000
--- a/bin/test/TEST.csh
+++ /dev/null
@@ -1,152 +0,0 @@
-# @(#)TEST.csh 5.2 (Berkeley) 4/30/93
-# $FreeBSD$
-
-#alias t '/usr/src/bin/test/obj/test \!*; echo $status'
-alias t '/bin/test \!*; echo $status'
-
-echo 't -b /dev/ttyp2'
-t -b /dev/ttyp2
-echo 't -b /dev/jb1a'
-t -b /dev/jb1a
-
-echo 't -c test.c'
-t -c test.c
-echo 't -c /dev/tty'
-t -c /dev/tty
-
-echo 't -d test.c'
-t -d test.c
-echo 't -d /etc'
-t -d /etc
-
-echo 't -e noexist'
-t -e noexist
-echo 't -e test.c'
-t -e test.c
-
-echo 't -f noexist'
-t -f noexist
-echo 't -f /dev/tty'
-t -f /dev/tty
-echo 't -f test.c'
-t -f test.c
-
-echo 't -g test.c'
-t -g test.c
-echo 't -g /bin/ps'
-t -g /bin/ps
-
-echo 't -n ""'
-t -n ""
-echo 't -n "hello"'
-t -n "hello"
-
-echo 't -p test.c'
-t -p test.c
-
-echo 't -r noexist'
-t -r noexist
-echo 't -r /etc/master.passwd'
-t -r /etc/master.passwd
-echo 't -r test.c'
-t -r test.c
-
-echo 't -s noexist'
-t -s noexist
-echo 't -s /dev/null'
-t -s /dev/null
-echo 't -s test.c'
-t -s test.c
-
-echo 't -t 20'
-t -t 20
-echo 't -t 0'
-t -t 0
-
-echo 't -u test.c'
-t -u test.c
-echo 't -u /bin/rcp'
-t -u /bin/rcp
-
-echo 't -w noexist'
-t -w noexist
-echo 't -w /etc/master.passwd'
-t -w /etc/master.passwd
-echo 't -w /dev/null'
-t -w /dev/null
-
-echo 't -x noexist'
-t -x noexist
-echo 't -x /bin/ps'
-t -x /bin/ps
-echo 't -x /etc/motd'
-t -x /etc/motd
-
-echo 't -z ""'
-t -z ""
-echo 't -z "foo"'
-t -z "foo"
-
-echo 't "foo"'
-t "foo"
-echo 't ""'
-t ""
-
-echo 't "hello" = "hello"'
-t "hello" = "hello"
-echo 't "hello" = "goodbye"'
-t "hello" = "goodbye"
-
-echo 't "hello" != "hello"'
-t "hello" != "hello"
-echo 't "hello" != "goodbye"'
-t "hello" != "goodbye"
-
-echo 't 200 -eq 200'
-t 200 -eq 200
-echo 't 34 -eq 222'
-t 34 -eq 222
-
-echo 't 200 -ne 200'
-t 200 -ne 200
-echo 't 34 -ne 222'
-t 34 -ne 222
-
-echo 't 200 -gt 200'
-t 200 -gt 200
-echo 't 340 -gt 222'
-t 340 -gt 222
-
-echo 't 200 -ge 200'
-t 200 -ge 200
-echo 't 34 -ge 222'
-t 34 -ge 222
-
-echo 't 200 -lt 200'
-t 200 -lt 200
-echo 't 34 -lt 222'
-t 34 -lt 222
-
-echo 't 200 -le 200'
-t 200 -le 200
-echo 't 340 -le 222'
-t 340 -le 222
-
-echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
-t 700 -le 1000 -a -n "1" -a "20" = "20"
-echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
-t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
-
-echo 't -5 -eq 5'
-t -5 -eq 5
-
-
-echo 't foo -a ""'
-t foo -a ""
-echo 't "" -a foo'
-t "" -a foo
-echo 't "" -a ""'
-t "" -a ""
-echo 't "" -o ""'
-t "" -o ""
-
diff --git a/contrib/binutils/bfd/opncls.c b/contrib/binutils/bfd/opncls.c
index 4457a79..9e0cc26 100644
--- a/contrib/binutils/bfd/opncls.c
+++ b/contrib/binutils/bfd/opncls.c
@@ -1465,7 +1465,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
debuglink_size &= ~3;
debuglink_size += 4;
- contents = malloc (debuglink_size);
+ contents = bfd_zmalloc (debuglink_size);
if (contents == NULL)
{
/* XXX Should we delete the section from the bfd ? */
diff --git a/contrib/bzip2/CHANGES b/contrib/bzip2/CHANGES
index 6e4f65e..81e97ca 100644
--- a/contrib/bzip2/CHANGES
+++ b/contrib/bzip2/CHANGES
@@ -2,8 +2,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -317,3 +317,11 @@ Fixes some minor bugs since the last version, 1.0.3.
~~~~~~~~~~~~~~~~~
Security fix only. Fixes CERT-FI 20469 as it applies to bzip2.
+
+1.0.6 (6 Sept 10)
+~~~~~~~~~~~~~~~~~
+
+* Security fix for CVE-2010-0405. This was reported by Mikolaj
+ Izdebski.
+
+* Make the documentation build on Ubuntu 10.04
diff --git a/contrib/bzip2/LICENSE b/contrib/bzip2/LICENSE
index f420cff..cc61417 100644
--- a/contrib/bzip2/LICENSE
+++ b/contrib/bzip2/LICENSE
@@ -2,7 +2,7 @@
--------------------------------------------------------------------------
This program, "bzip2", the associated library "libbzip2", and all
-documentation, are copyright (C) 1996-2007 Julian R Seward. All
+documentation, are copyright (C) 1996-2010 Julian R Seward. All
rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,6 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, jseward@bzip.org
-bzip2/libbzip2 version 1.0.5 of 10 December 2007
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
--------------------------------------------------------------------------
diff --git a/contrib/bzip2/Makefile b/contrib/bzip2/Makefile
index eb09753..9754ddf 100644
--- a/contrib/bzip2/Makefile
+++ b/contrib/bzip2/Makefile
@@ -2,8 +2,8 @@
# This file is part of bzip2/libbzip2, a program and library for
# lossless, block-sorting data compression.
#
-# bzip2/libbzip2 version 1.0.5 of 10 December 2007
-# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+# bzip2/libbzip2 version 1.0.6 of 6 September 2010
+# Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
#
# Please read the WARNING, DISCLAIMER and PATENTS sections in the
# README file.
@@ -137,7 +137,7 @@ bzip2recover.o: bzip2recover.c
distclean: clean
rm -f manual.ps manual.html manual.pdf
-DISTNAME=bzip2-1.0.5
+DISTNAME=bzip2-1.0.6
dist: check manual
rm -f $(DISTNAME)
ln -s -f . $(DISTNAME)
diff --git a/contrib/bzip2/Makefile-libbz2_so b/contrib/bzip2/Makefile-libbz2_so
index 9a13c77..e58791b 100644
--- a/contrib/bzip2/Makefile-libbz2_so
+++ b/contrib/bzip2/Makefile-libbz2_so
@@ -1,6 +1,6 @@
# This Makefile builds a shared version of the library,
-# libbz2.so.1.0.4, with soname libbz2.so.1.0,
+# libbz2.so.1.0.6, with soname libbz2.so.1.0,
# at least on x86-Linux (RedHat 7.2),
# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).
# Please see the README file for some important info
@@ -10,8 +10,8 @@
# This file is part of bzip2/libbzip2, a program and library for
# lossless, block-sorting data compression.
#
-# bzip2/libbzip2 version 1.0.5 of 10 December 2007
-# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+# bzip2/libbzip2 version 1.0.6 of 6 September 2010
+# Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
#
# Please read the WARNING, DISCLAIMER and PATENTS sections in the
# README file.
@@ -35,13 +35,13 @@ OBJS= blocksort.o \
bzlib.o
all: $(OBJS)
- $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.4 $(OBJS)
- $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.4
+ $(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 $(OBJS)
+ $(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.6
rm -f libbz2.so.1.0
- ln -s libbz2.so.1.0.4 libbz2.so.1.0
+ ln -s libbz2.so.1.0.6 libbz2.so.1.0
clean:
- rm -f $(OBJS) bzip2.o libbz2.so.1.0.4 libbz2.so.1.0 bzip2-shared
+ rm -f $(OBJS) bzip2.o libbz2.so.1.0.6 libbz2.so.1.0 bzip2-shared
blocksort.o: blocksort.c
$(CC) $(CFLAGS) -c blocksort.c
diff --git a/contrib/bzip2/README b/contrib/bzip2/README
index e17a84e..9fb0f63 100644
--- a/contrib/bzip2/README
+++ b/contrib/bzip2/README
@@ -6,8 +6,8 @@ This version is fully compatible with the previous public releases.
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
-bzip2/libbzip2 version 1.0.5 of 10 December 2007
-Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
+Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
@@ -181,6 +181,10 @@ WHAT'S NEW IN 1.0.5 ?
See the CHANGES file.
+WHAT'S NEW IN 1.0.6 ?
+
+ See the CHANGES file.
+
I hope you find bzip2 useful. Feel free to contact me at
jseward@bzip.org
@@ -208,3 +212,4 @@ Cambridge, UK.
15 February 2005 (bzip2, version 1.0.3)
20 December 2006 (bzip2, version 1.0.4)
10 December 2007 (bzip2, version 1.0.5)
+ 6 Sept 2010 (bzip2, version 1.0.6)
diff --git a/contrib/bzip2/README.COMPILATION.PROBLEMS b/contrib/bzip2/README.COMPILATION.PROBLEMS
index 22b95c6..667d0d6 100644
--- a/contrib/bzip2/README.COMPILATION.PROBLEMS
+++ b/contrib/bzip2/README.COMPILATION.PROBLEMS
@@ -2,8 +2,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
-bzip2/libbzip2 version 1.0.5 of 10 December 2007
-Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
+Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -12,7 +12,7 @@ This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
-bzip2-1.0.5 should compile without problems on the vast majority of
+bzip2-1.0.6 should compile without problems on the vast majority of
platforms. Using the supplied Makefile, I've built and tested it
myself for x86-linux and amd64-linux. With makefile.msc, Visual C++
6.0 and nmake, you can build a native Win32 version too. Large file
diff --git a/contrib/bzip2/blocksort.c b/contrib/bzip2/blocksort.c
index bd2dec1..d0d662c 100644
--- a/contrib/bzip2/blocksort.c
+++ b/contrib/bzip2/blocksort.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/bzip2.1 b/contrib/bzip2/bzip2.1
index a313f2d..ce3a78e 100644
--- a/contrib/bzip2/bzip2.1
+++ b/contrib/bzip2/bzip2.1
@@ -1,7 +1,7 @@
.PU
.TH bzip2 1
.SH NAME
-bzip2, bunzip2 \- a block-sorting file compressor, v1.0.4
+bzip2, bunzip2 \- a block-sorting file compressor, v1.0.6
.br
bzcat \- decompresses files to stdout
.br
@@ -405,11 +405,11 @@ I/O error messages are not as helpful as they could be.
tries hard to detect I/O errors and exit cleanly, but the details of
what the problem is sometimes seem rather misleading.
-This manual page pertains to version 1.0.4 of
+This manual page pertains to version 1.0.6 of
.I bzip2.
Compressed data created by this version is entirely forwards and
backwards compatible with the previous public releases, versions
-0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 1.0.2 and 1.0.3, but with the following
+0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1, 1.0.2 and above, but with the following
exception: 0.9.0 and above can correctly decompress multiple
concatenated compressed files. 0.1pl2 cannot do this; it will stop
after decompressing just the first file in the stream.
diff --git a/contrib/bzip2/bzip2.c b/contrib/bzip2/bzip2.c
index 3904107..6de9d1d 100644
--- a/contrib/bzip2/bzip2.c
+++ b/contrib/bzip2/bzip2.c
@@ -7,8 +7,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -1605,11 +1605,11 @@ void license ( void )
"bzip2, a block-sorting file compressor. "
"Version %s.\n"
" \n"
- " Copyright (C) 1996-2007 by Julian Seward.\n"
+ " Copyright (C) 1996-2010 by Julian Seward.\n"
" \n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms set out in the LICENSE file, which is included\n"
- " in the bzip2-1.0.5 source distribution.\n"
+ " in the bzip2-1.0.6 source distribution.\n"
" \n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
diff --git a/contrib/bzip2/bzip2recover.c b/contrib/bzip2/bzip2recover.c
index 5f6d621..f9de049 100644
--- a/contrib/bzip2/bzip2recover.c
+++ b/contrib/bzip2/bzip2recover.c
@@ -7,8 +7,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -313,7 +313,7 @@ Int32 main ( Int32 argc, Char** argv )
inFileName[0] = outFileName[0] = 0;
fprintf ( stderr,
- "bzip2recover 1.0.5: extracts blocks from damaged .bz2 files.\n" );
+ "bzip2recover 1.0.6: extracts blocks from damaged .bz2 files.\n" );
if (argc != 2) {
fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
diff --git a/contrib/bzip2/bzlib.c b/contrib/bzip2/bzlib.c
index 85dc8ff..c02d076 100644
--- a/contrib/bzip2/bzlib.c
+++ b/contrib/bzip2/bzlib.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/bzlib.h b/contrib/bzip2/bzlib.h
index c5b75d6..8277123 100644
--- a/contrib/bzip2/bzlib.h
+++ b/contrib/bzip2/bzlib.h
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/bzlib_private.h b/contrib/bzip2/bzlib_private.h
index 2342787..5d0217f 100644
--- a/contrib/bzip2/bzlib_private.h
+++ b/contrib/bzip2/bzlib_private.h
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -36,7 +36,7 @@
/*-- General stuff. --*/
-#define BZ_VERSION "1.0.5, 10-Dec-2007"
+#define BZ_VERSION "1.0.6, 6-Sept-2010"
typedef char Char;
typedef unsigned char Bool;
diff --git a/contrib/bzip2/compress.c b/contrib/bzip2/compress.c
index 8c80a07..caf7696 100644
--- a/contrib/bzip2/compress.c
+++ b/contrib/bzip2/compress.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/crctable.c b/contrib/bzip2/crctable.c
index 215687b..1fea7e9 100644
--- a/contrib/bzip2/crctable.c
+++ b/contrib/bzip2/crctable.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/decompress.c b/contrib/bzip2/decompress.c
index af1d4d0..311f566 100644
--- a/contrib/bzip2/decompress.c
+++ b/contrib/bzip2/decompress.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
@@ -492,15 +492,28 @@ Int32 BZ2_decompress ( DState* s )
RETURN(BZ_DATA_ERROR);
/*-- Set up cftab to facilitate generation of T^(-1) --*/
+ /* Check: unzftab entries in range. */
+ for (i = 0; i <= 255; i++) {
+ if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
+ RETURN(BZ_DATA_ERROR);
+ }
+ /* Actually generate cftab. */
s->cftab[0] = 0;
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
+ /* Check: cftab entries in range. */
for (i = 0; i <= 256; i++) {
if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
/* s->cftab[i] can legitimately be == nblock */
RETURN(BZ_DATA_ERROR);
}
}
+ /* Check: cftab entries non-descending. */
+ for (i = 1; i <= 256; i++) {
+ if (s->cftab[i-1] > s->cftab[i]) {
+ RETURN(BZ_DATA_ERROR);
+ }
+ }
s->state_out_len = 0;
s->state_out_ch = 0;
diff --git a/contrib/bzip2/huffman.c b/contrib/bzip2/huffman.c
index 87e79e3..2283fdb 100644
--- a/contrib/bzip2/huffman.c
+++ b/contrib/bzip2/huffman.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/randtable.c b/contrib/bzip2/randtable.c
index 068b763..6d62459 100644
--- a/contrib/bzip2/randtable.c
+++ b/contrib/bzip2/randtable.c
@@ -8,8 +8,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/spewG.c b/contrib/bzip2/spewG.c
index 5892b92..14a3649 100644
--- a/contrib/bzip2/spewG.c
+++ b/contrib/bzip2/spewG.c
@@ -13,8 +13,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/bzip2/unzcrash.c b/contrib/bzip2/unzcrash.c
index a1b7546..7041da5 100644
--- a/contrib/bzip2/unzcrash.c
+++ b/contrib/bzip2/unzcrash.c
@@ -17,8 +17,8 @@
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
- bzip2/libbzip2 version 1.0.5 of 10 December 2007
- Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
+ bzip2/libbzip2 version 1.0.6 of 6 September 2010
+ Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
diff --git a/contrib/compiler-rt/BlocksRuntime/Block.h b/contrib/compiler-rt/BlocksRuntime/Block.h
new file mode 100644
index 0000000..55cdd01
--- /dev/null
+++ b/contrib/compiler-rt/BlocksRuntime/Block.h
@@ -0,0 +1,59 @@
+/*
+ * Block.h
+ *
+ * Copyright 2008-2010 Apple, Inc. 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.
+ *
+ */
+
+#ifndef _BLOCK_H_
+#define _BLOCK_H_
+
+#if !defined(BLOCK_EXPORT)
+# if defined(__cplusplus)
+# define BLOCK_EXPORT extern "C"
+# else
+# define BLOCK_EXPORT extern
+# endif
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Create a heap based copy of a Block or simply add a reference to an existing one.
+ * This must be paired with Block_release to recover memory, even when running
+ * under Objective-C Garbage Collection.
+ */
+BLOCK_EXPORT void *_Block_copy(const void *aBlock);
+
+/* Lose the reference, and if heap based and last reference, recover the memory. */
+BLOCK_EXPORT void _Block_release(const void *aBlock);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/* Type correct macros. */
+
+#define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
+#define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
+
+
+#endif
diff --git a/contrib/compiler-rt/BlocksRuntime/Block_private.h b/contrib/compiler-rt/BlocksRuntime/Block_private.h
new file mode 100644
index 0000000..8ae8218
--- /dev/null
+++ b/contrib/compiler-rt/BlocksRuntime/Block_private.h
@@ -0,0 +1,179 @@
+/*
+ * Block_private.h
+ *
+ * Copyright 2008-2010 Apple, Inc. 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.
+ *
+ */
+
+#ifndef _BLOCK_PRIVATE_H_
+#define _BLOCK_PRIVATE_H_
+
+#if !defined(BLOCK_EXPORT)
+# if defined(__cplusplus)
+# define BLOCK_EXPORT extern "C"
+# else
+# define BLOCK_EXPORT extern
+# endif
+#endif
+
+#ifndef _MSC_VER
+#include <stdbool.h>
+#else
+/* MSVC doesn't have <stdbool.h>. Compensate. */
+typedef char bool;
+#define true (bool)1
+#define false (bool)0
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+enum {
+ BLOCK_REFCOUNT_MASK = (0xffff),
+ BLOCK_NEEDS_FREE = (1 << 24),
+ BLOCK_HAS_COPY_DISPOSE = (1 << 25),
+ BLOCK_HAS_CTOR = (1 << 26), /* Helpers have C++ code. */
+ BLOCK_IS_GC = (1 << 27),
+ BLOCK_IS_GLOBAL = (1 << 28),
+ BLOCK_HAS_DESCRIPTOR = (1 << 29)
+};
+
+
+/* Revised new layout. */
+struct Block_descriptor {
+ unsigned long int reserved;
+ unsigned long int size;
+ void (*copy)(void *dst, void *src);
+ void (*dispose)(void *);
+};
+
+
+struct Block_layout {
+ void *isa;
+ int flags;
+ int reserved;
+ void (*invoke)(void *, ...);
+ struct Block_descriptor *descriptor;
+ /* Imported variables. */
+};
+
+
+struct Block_byref {
+ void *isa;
+ struct Block_byref *forwarding;
+ int flags; /* refcount; */
+ int size;
+ void (*byref_keep)(struct Block_byref *dst, struct Block_byref *src);
+ void (*byref_destroy)(struct Block_byref *);
+ /* long shared[0]; */
+};
+
+
+struct Block_byref_header {
+ void *isa;
+ struct Block_byref *forwarding;
+ int flags;
+ int size;
+};
+
+
+/* Runtime support functions used by compiler when generating copy/dispose helpers. */
+
+enum {
+ /* See function implementation for a more complete description of these fields and combinations */
+ BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), block, ... */
+ BLOCK_FIELD_IS_BLOCK = 7, /* a block variable */
+ BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the __block variable */
+ BLOCK_FIELD_IS_WEAK = 16, /* declared __weak, only used in byref copy helpers */
+ BLOCK_BYREF_CALLER = 128 /* called from __block (byref) copy/dispose support routines. */
+};
+
+/* Runtime entry point called by compiler when assigning objects inside copy helper routines */
+BLOCK_EXPORT void _Block_object_assign(void *destAddr, const void *object, const int flags);
+ /* BLOCK_FIELD_IS_BYREF is only used from within block copy helpers */
+
+
+/* runtime entry point called by the compiler when disposing of objects inside dispose helper routine */
+BLOCK_EXPORT void _Block_object_dispose(const void *object, const int flags);
+
+
+
+/* Other support functions */
+
+/* Runtime entry to get total size of a closure */
+BLOCK_EXPORT unsigned long int Block_size(void *block_basic);
+
+
+
+/* the raw data space for runtime classes for blocks */
+/* class+meta used for stack, malloc, and collectable based blocks */
+BLOCK_EXPORT void * _NSConcreteStackBlock[32];
+BLOCK_EXPORT void * _NSConcreteMallocBlock[32];
+BLOCK_EXPORT void * _NSConcreteAutoBlock[32];
+BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32];
+BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
+BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32];
+
+
+/* the intercept routines that must be used under GC */
+BLOCK_EXPORT void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
+ void (*setHasRefcount)(const void *, const bool),
+ void (*gc_assign_strong)(void *, void **),
+ void (*gc_assign_weak)(const void *, void *),
+ void (*gc_memmove)(void *, void *, unsigned long));
+
+/* earlier version, now simply transitional */
+BLOCK_EXPORT void _Block_use_GC5( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
+ void (*setHasRefcount)(const void *, const bool),
+ void (*gc_assign_strong)(void *, void **),
+ void (*gc_assign_weak)(const void *, void *));
+
+BLOCK_EXPORT void _Block_use_RR( void (*retain)(const void *),
+ void (*release)(const void *));
+
+/* make a collectable GC heap based Block. Not useful under non-GC. */
+BLOCK_EXPORT void *_Block_copy_collectable(const void *aBlock);
+
+/* thread-unsafe diagnostic */
+BLOCK_EXPORT const char *_Block_dump(const void *block);
+
+
+/* Obsolete */
+
+/* first layout */
+struct Block_basic {
+ void *isa;
+ int Block_flags; /* int32_t */
+ int Block_size; /* XXX should be packed into Block_flags */
+ void (*Block_invoke)(void *);
+ void (*Block_copy)(void *dst, void *src); /* iff BLOCK_HAS_COPY_DISPOSE */
+ void (*Block_dispose)(void *); /* iff BLOCK_HAS_COPY_DISPOSE */
+ /* long params[0]; // where const imports, __block storage references, etc. get laid down */
+};
+
+
+#if defined(__cplusplus)
+}
+#endif
+
+
+#endif /* _BLOCK_PRIVATE_H_ */
diff --git a/contrib/compiler-rt/BlocksRuntime/data.c b/contrib/compiler-rt/BlocksRuntime/data.c
new file mode 100644
index 0000000..b4eb02e
--- /dev/null
+++ b/contrib/compiler-rt/BlocksRuntime/data.c
@@ -0,0 +1,41 @@
+/*
+ * data.c
+ *
+ * Copyright 2008-2010 Apple, Inc. 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.
+ *
+ */
+
+/********************
+NSBlock support
+
+We allocate space and export a symbol to be used as the Class for the on-stack and malloc'ed copies until ObjC arrives on the scene. These data areas are set up by Foundation to link in as real classes post facto.
+
+We keep these in a separate file so that we can include the runtime code in test subprojects but not include the data so that compiled code that sees the data in libSystem doesn't get confused by a second copy. Somehow these don't get unified in a common block.
+**********************/
+
+void * _NSConcreteStackBlock[32] = { 0 };
+void * _NSConcreteMallocBlock[32] = { 0 };
+void * _NSConcreteAutoBlock[32] = { 0 };
+void * _NSConcreteFinalizingBlock[32] = { 0 };
+void * _NSConcreteGlobalBlock[32] = { 0 };
+void * _NSConcreteWeakBlockVariable[32] = { 0 };
+
+void _Block_copy_error(void) {
+}
diff --git a/contrib/compiler-rt/BlocksRuntime/runtime.c b/contrib/compiler-rt/BlocksRuntime/runtime.c
new file mode 100644
index 0000000..a059c22
--- /dev/null
+++ b/contrib/compiler-rt/BlocksRuntime/runtime.c
@@ -0,0 +1,700 @@
+/*
+ * runtime.c
+ *
+ * Copyright 2008-2010 Apple, Inc. 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.
+ *
+ */
+
+#include "Block_private.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "config.h"
+
+#ifdef HAVE_AVAILABILITY_MACROS_H
+#include <AvailabilityMacros.h>
+#endif /* HAVE_AVAILABILITY_MACROS_H */
+
+#ifdef HAVE_TARGET_CONDITIONALS_H
+#include <TargetConditionals.h>
+#endif /* HAVE_TARGET_CONDITIONALS_H */
+
+#if defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_INT) && defined(HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG)
+
+#ifdef HAVE_LIBKERN_OSATOMIC_H
+#include <libkern/OSAtomic.h>
+#endif /* HAVE_LIBKERN_OSATOMIC_H */
+
+#elif defined(__WIN32__) || defined(_WIN32)
+#define _CRT_SECURE_NO_WARNINGS 1
+#include <windows.h>
+
+static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst) {
+ /* fixme barrier is overkill -- see objc-os.h */
+ long original = InterlockedCompareExchange(dst, newl, oldl);
+ return (original == oldl);
+}
+
+static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst) {
+ /* fixme barrier is overkill -- see objc-os.h */
+ int original = InterlockedCompareExchange(dst, newi, oldi);
+ return (original == oldi);
+}
+
+/*
+ * Check to see if the GCC atomic built-ins are available. If we're on
+ * a 64-bit system, make sure we have an 8-byte atomic function
+ * available.
+ *
+ */
+
+#elif defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT) && defined(HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG)
+
+static __inline bool OSAtomicCompareAndSwapLong(long oldl, long newl, long volatile *dst) {
+ return __sync_bool_compare_and_swap(dst, oldl, newl);
+}
+
+static __inline bool OSAtomicCompareAndSwapInt(int oldi, int newi, int volatile *dst) {
+ return __sync_bool_compare_and_swap(dst, oldi, newi);
+}
+
+#else
+#error unknown atomic compare-and-swap primitive
+#endif /* HAVE_OSATOMIC_COMPARE_AND_SWAP_INT && HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG */
+
+
+/*
+ * Globals:
+ */
+
+static void *_Block_copy_class = _NSConcreteMallocBlock;
+static void *_Block_copy_finalizing_class = _NSConcreteMallocBlock;
+static int _Block_copy_flag = BLOCK_NEEDS_FREE;
+static int _Byref_flag_initial_value = BLOCK_NEEDS_FREE | 2;
+
+static const int WANTS_ONE = (1 << 16);
+
+static bool isGC = false;
+
+/*
+ * Internal Utilities:
+ */
+
+#if 0
+static unsigned long int latching_incr_long(unsigned long int *where) {
+ while (1) {
+ unsigned long int old_value = *(volatile unsigned long int *)where;
+ if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
+ return BLOCK_REFCOUNT_MASK;
+ }
+ if (OSAtomicCompareAndSwapLong(old_value, old_value+1, (volatile long int *)where)) {
+ return old_value+1;
+ }
+ }
+}
+#endif /* if 0 */
+
+static int latching_incr_int(int *where) {
+ while (1) {
+ int old_value = *(volatile int *)where;
+ if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
+ return BLOCK_REFCOUNT_MASK;
+ }
+ if (OSAtomicCompareAndSwapInt(old_value, old_value+1, (volatile int *)where)) {
+ return old_value+1;
+ }
+ }
+}
+
+#if 0
+static int latching_decr_long(unsigned long int *where) {
+ while (1) {
+ unsigned long int old_value = *(volatile int *)where;
+ if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
+ return BLOCK_REFCOUNT_MASK;
+ }
+ if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
+ return 0;
+ }
+ if (OSAtomicCompareAndSwapLong(old_value, old_value-1, (volatile long int *)where)) {
+ return old_value-1;
+ }
+ }
+}
+#endif /* if 0 */
+
+static int latching_decr_int(int *where) {
+ while (1) {
+ int old_value = *(volatile int *)where;
+ if ((old_value & BLOCK_REFCOUNT_MASK) == BLOCK_REFCOUNT_MASK) {
+ return BLOCK_REFCOUNT_MASK;
+ }
+ if ((old_value & BLOCK_REFCOUNT_MASK) == 0) {
+ return 0;
+ }
+ if (OSAtomicCompareAndSwapInt(old_value, old_value-1, (volatile int *)where)) {
+ return old_value-1;
+ }
+ }
+}
+
+
+/*
+ * GC support stub routines:
+ */
+#if 0
+#pragma mark GC Support Routines
+#endif /* if 0 */
+
+
+static void *_Block_alloc_default(const unsigned long size, const bool initialCountIsOne, const bool isObject) {
+ return malloc(size);
+}
+
+static void _Block_assign_default(void *value, void **destptr) {
+ *destptr = value;
+}
+
+static void _Block_setHasRefcount_default(const void *ptr, const bool hasRefcount) {
+}
+
+static void _Block_do_nothing(const void *aBlock) { }
+
+static void _Block_retain_object_default(const void *ptr) {
+ if (!ptr) return;
+}
+
+static void _Block_release_object_default(const void *ptr) {
+ if (!ptr) return;
+}
+
+static void _Block_assign_weak_default(const void *ptr, void *dest) {
+ *(void **)dest = (void *)ptr;
+}
+
+static void _Block_memmove_default(void *dst, void *src, unsigned long size) {
+ memmove(dst, src, (size_t)size);
+}
+
+static void _Block_memmove_gc_broken(void *dest, void *src, unsigned long size) {
+ void **destp = (void **)dest;
+ void **srcp = (void **)src;
+ while (size) {
+ _Block_assign_default(*srcp, destp);
+ destp++;
+ srcp++;
+ size -= sizeof(void *);
+ }
+}
+
+/*
+ * GC support callout functions - initially set to stub routines:
+ */
+
+static void *(*_Block_allocator)(const unsigned long, const bool isOne, const bool isObject) = _Block_alloc_default;
+static void (*_Block_deallocator)(const void *) = (void (*)(const void *))free;
+static void (*_Block_assign)(void *value, void **destptr) = _Block_assign_default;
+static void (*_Block_setHasRefcount)(const void *ptr, const bool hasRefcount) = _Block_setHasRefcount_default;
+static void (*_Block_retain_object)(const void *ptr) = _Block_retain_object_default;
+static void (*_Block_release_object)(const void *ptr) = _Block_release_object_default;
+static void (*_Block_assign_weak)(const void *dest, void *ptr) = _Block_assign_weak_default;
+static void (*_Block_memmove)(void *dest, void *src, unsigned long size) = _Block_memmove_default;
+
+
+/*
+ * GC support SPI functions - called from ObjC runtime and CoreFoundation:
+ */
+
+/* Public SPI
+ * Called from objc-auto to turn on GC.
+ * version 3, 4 arg, but changed 1st arg
+ */
+void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
+ void (*setHasRefcount)(const void *, const bool),
+ void (*gc_assign)(void *, void **),
+ void (*gc_assign_weak)(const void *, void *),
+ void (*gc_memmove)(void *, void *, unsigned long)) {
+
+ isGC = true;
+ _Block_allocator = alloc;
+ _Block_deallocator = _Block_do_nothing;
+ _Block_assign = gc_assign;
+ _Block_copy_flag = BLOCK_IS_GC;
+ _Block_copy_class = _NSConcreteAutoBlock;
+ /* blocks with ctors & dtors need to have the dtor run from a class with a finalizer */
+ _Block_copy_finalizing_class = _NSConcreteFinalizingBlock;
+ _Block_setHasRefcount = setHasRefcount;
+ _Byref_flag_initial_value = BLOCK_IS_GC; // no refcount
+ _Block_retain_object = _Block_do_nothing;
+ _Block_release_object = _Block_do_nothing;
+ _Block_assign_weak = gc_assign_weak;
+ _Block_memmove = gc_memmove;
+}
+
+/* transitional */
+void _Block_use_GC5( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),
+ void (*setHasRefcount)(const void *, const bool),
+ void (*gc_assign)(void *, void **),
+ void (*gc_assign_weak)(const void *, void *)) {
+ /* until objc calls _Block_use_GC it will call us; supply a broken internal memmove implementation until then */
+ _Block_use_GC(alloc, setHasRefcount, gc_assign, gc_assign_weak, _Block_memmove_gc_broken);
+}
+
+
+/*
+ * Called from objc-auto to alternatively turn on retain/release.
+ * Prior to this the only "object" support we can provide is for those
+ * super special objects that live in libSystem, namely dispatch queues.
+ * Blocks and Block_byrefs have their own special entry points.
+ *
+ */
+void _Block_use_RR( void (*retain)(const void *),
+ void (*release)(const void *)) {
+ _Block_retain_object = retain;
+ _Block_release_object = release;
+}
+
+/*
+ * Internal Support routines for copying:
+ */
+
+#if 0
+#pragma mark Copy/Release support
+#endif /* if 0 */
+
+/* Copy, or bump refcount, of a block. If really copying, call the copy helper if present. */
+static void *_Block_copy_internal(const void *arg, const int flags) {
+ struct Block_layout *aBlock;
+ const bool wantsOne = (WANTS_ONE & flags) == WANTS_ONE;
+
+ //printf("_Block_copy_internal(%p, %x)\n", arg, flags);
+ if (!arg) return NULL;
+
+
+ // The following would be better done as a switch statement
+ aBlock = (struct Block_layout *)arg;
+ if (aBlock->flags & BLOCK_NEEDS_FREE) {
+ // latches on high
+ latching_incr_int(&aBlock->flags);
+ return aBlock;
+ }
+ else if (aBlock->flags & BLOCK_IS_GC) {
+ // GC refcounting is expensive so do most refcounting here.
+ if (wantsOne && ((latching_incr_int(&aBlock->flags) & BLOCK_REFCOUNT_MASK) == 1)) {
+ // Tell collector to hang on this - it will bump the GC refcount version
+ _Block_setHasRefcount(aBlock, true);
+ }
+ return aBlock;
+ }
+ else if (aBlock->flags & BLOCK_IS_GLOBAL) {
+ return aBlock;
+ }
+
+ // Its a stack block. Make a copy.
+ if (!isGC) {
+ struct Block_layout *result = malloc(aBlock->descriptor->size);
+ if (!result) return (void *)0;
+ memmove(result, aBlock, aBlock->descriptor->size); // bitcopy first
+ // reset refcount
+ result->flags &= ~(BLOCK_REFCOUNT_MASK); // XXX not needed
+ result->flags |= BLOCK_NEEDS_FREE | 1;
+ result->isa = _NSConcreteMallocBlock;
+ if (result->flags & BLOCK_HAS_COPY_DISPOSE) {
+ //printf("calling block copy helper %p(%p, %p)...\n", aBlock->descriptor->copy, result, aBlock);
+ (*aBlock->descriptor->copy)(result, aBlock); // do fixup
+ }
+ return result;
+ }
+ else {
+ // Under GC want allocation with refcount 1 so we ask for "true" if wantsOne
+ // This allows the copy helper routines to make non-refcounted block copies under GC
+ unsigned long int flags = aBlock->flags;
+ bool hasCTOR = (flags & BLOCK_HAS_CTOR) != 0;
+ struct Block_layout *result = _Block_allocator(aBlock->descriptor->size, wantsOne, hasCTOR);
+ if (!result) return (void *)0;
+ memmove(result, aBlock, aBlock->descriptor->size); // bitcopy first
+ // reset refcount
+ // if we copy a malloc block to a GC block then we need to clear NEEDS_FREE.
+ flags &= ~(BLOCK_NEEDS_FREE|BLOCK_REFCOUNT_MASK); // XXX not needed
+ if (wantsOne)
+ flags |= BLOCK_IS_GC | 1;
+ else
+ flags |= BLOCK_IS_GC;
+ result->flags = flags;
+ if (flags & BLOCK_HAS_COPY_DISPOSE) {
+ //printf("calling block copy helper...\n");
+ (*aBlock->descriptor->copy)(result, aBlock); // do fixup
+ }
+ if (hasCTOR) {
+ result->isa = _NSConcreteFinalizingBlock;
+ }
+ else {
+ result->isa = _NSConcreteAutoBlock;
+ }
+ return result;
+ }
+}
+
+
+/*
+ * Runtime entry points for maintaining the sharing knowledge of byref data blocks.
+ *
+ * A closure has been copied and its fixup routine is asking us to fix up the reference to the shared byref data
+ * Closures that aren't copied must still work, so everyone always accesses variables after dereferencing the forwarding ptr.
+ * We ask if the byref pointer that we know about has already been copied to the heap, and if so, increment it.
+ * Otherwise we need to copy it and update the stack forwarding pointer
+ * XXX We need to account for weak/nonretained read-write barriers.
+ */
+
+static void _Block_byref_assign_copy(void *dest, const void *arg, const int flags) {
+ struct Block_byref **destp = (struct Block_byref **)dest;
+ struct Block_byref *src = (struct Block_byref *)arg;
+
+ //printf("_Block_byref_assign_copy called, byref destp %p, src %p, flags %x\n", destp, src, flags);
+ //printf("src dump: %s\n", _Block_byref_dump(src));
+ if (src->forwarding->flags & BLOCK_IS_GC) {
+ ; // don't need to do any more work
+ }
+ else if ((src->forwarding->flags & BLOCK_REFCOUNT_MASK) == 0) {
+ //printf("making copy\n");
+ // src points to stack
+ bool isWeak = ((flags & (BLOCK_FIELD_IS_BYREF|BLOCK_FIELD_IS_WEAK)) == (BLOCK_FIELD_IS_BYREF|BLOCK_FIELD_IS_WEAK));
+ // if its weak ask for an object (only matters under GC)
+ struct Block_byref *copy = (struct Block_byref *)_Block_allocator(src->size, false, isWeak);
+ copy->flags = src->flags | _Byref_flag_initial_value; // non-GC one for caller, one for stack
+ copy->forwarding = copy; // patch heap copy to point to itself (skip write-barrier)
+ src->forwarding = copy; // patch stack to point to heap copy
+ copy->size = src->size;
+ if (isWeak) {
+ copy->isa = &_NSConcreteWeakBlockVariable; // mark isa field so it gets weak scanning
+ }
+ if (src->flags & BLOCK_HAS_COPY_DISPOSE) {
+ // Trust copy helper to copy everything of interest
+ // If more than one field shows up in a byref block this is wrong XXX
+ copy->byref_keep = src->byref_keep;
+ copy->byref_destroy = src->byref_destroy;
+ (*src->byref_keep)(copy, src);
+ }
+ else {
+ // just bits. Blast 'em using _Block_memmove in case they're __strong
+ _Block_memmove(
+ (void *)&copy->byref_keep,
+ (void *)&src->byref_keep,
+ src->size - sizeof(struct Block_byref_header));
+ }
+ }
+ // already copied to heap
+ else if ((src->forwarding->flags & BLOCK_NEEDS_FREE) == BLOCK_NEEDS_FREE) {
+ latching_incr_int(&src->forwarding->flags);
+ }
+ // assign byref data block pointer into new Block
+ _Block_assign(src->forwarding, (void **)destp);
+}
+
+// Old compiler SPI
+static void _Block_byref_release(const void *arg) {
+ struct Block_byref *shared_struct = (struct Block_byref *)arg;
+ int refcount;
+
+ // dereference the forwarding pointer since the compiler isn't doing this anymore (ever?)
+ shared_struct = shared_struct->forwarding;
+
+ //printf("_Block_byref_release %p called, flags are %x\n", shared_struct, shared_struct->flags);
+ // To support C++ destructors under GC we arrange for there to be a finalizer for this
+ // by using an isa that directs the code to a finalizer that calls the byref_destroy method.
+ if ((shared_struct->flags & BLOCK_NEEDS_FREE) == 0) {
+ return; // stack or GC or global
+ }
+ refcount = shared_struct->flags & BLOCK_REFCOUNT_MASK;
+ if (refcount <= 0) {
+ printf("_Block_byref_release: Block byref data structure at %p underflowed\n", arg);
+ }
+ else if ((latching_decr_int(&shared_struct->flags) & BLOCK_REFCOUNT_MASK) == 0) {
+ //printf("disposing of heap based byref block\n");
+ if (shared_struct->flags & BLOCK_HAS_COPY_DISPOSE) {
+ //printf("calling out to helper\n");
+ (*shared_struct->byref_destroy)(shared_struct);
+ }
+ _Block_deallocator((struct Block_layout *)shared_struct);
+ }
+}
+
+
+/*
+ *
+ * API supporting SPI
+ * _Block_copy, _Block_release, and (old) _Block_destroy
+ *
+ */
+
+#if 0
+#pragma mark SPI/API
+#endif /* if 0 */
+
+void *_Block_copy(const void *arg) {
+ return _Block_copy_internal(arg, WANTS_ONE);
+}
+
+
+// API entry point to release a copied Block
+void _Block_release(void *arg) {
+ struct Block_layout *aBlock = (struct Block_layout *)arg;
+ int32_t newCount;
+ if (!aBlock) return;
+ newCount = latching_decr_int(&aBlock->flags) & BLOCK_REFCOUNT_MASK;
+ if (newCount > 0) return;
+ // Hit zero
+ if (aBlock->flags & BLOCK_IS_GC) {
+ // Tell GC we no longer have our own refcounts. GC will decr its refcount
+ // and unless someone has done a CFRetain or marked it uncollectable it will
+ // now be subject to GC reclamation.
+ _Block_setHasRefcount(aBlock, false);
+ }
+ else if (aBlock->flags & BLOCK_NEEDS_FREE) {
+ if (aBlock->flags & BLOCK_HAS_COPY_DISPOSE)(*aBlock->descriptor->dispose)(aBlock);
+ _Block_deallocator(aBlock);
+ }
+ else if (aBlock->flags & BLOCK_IS_GLOBAL) {
+ ;
+ }
+ else {
+ printf("Block_release called upon a stack Block: %p, ignored\n", (void *)aBlock);
+ }
+}
+
+
+
+// Old Compiler SPI point to release a copied Block used by the compiler in dispose helpers
+static void _Block_destroy(const void *arg) {
+ struct Block_layout *aBlock;
+ if (!arg) return;
+ aBlock = (struct Block_layout *)arg;
+ if (aBlock->flags & BLOCK_IS_GC) {
+ // assert(aBlock->Block_flags & BLOCK_HAS_CTOR);
+ return; // ignore, we are being called because of a DTOR
+ }
+ _Block_release(aBlock);
+}
+
+
+
+/*
+ *
+ * SPI used by other layers
+ *
+ */
+
+// SPI, also internal. Called from NSAutoBlock only under GC
+void *_Block_copy_collectable(const void *aBlock) {
+ return _Block_copy_internal(aBlock, 0);
+}
+
+
+// SPI
+unsigned long int Block_size(void *arg) {
+ return ((struct Block_layout *)arg)->descriptor->size;
+}
+
+
+#if 0
+#pragma mark Compiler SPI entry points
+#endif /* if 0 */
+
+
+/*******************************************************
+
+Entry points used by the compiler - the real API!
+
+
+A Block can reference four different kinds of things that require help when the Block is copied to the heap.
+1) C++ stack based objects
+2) References to Objective-C objects
+3) Other Blocks
+4) __block variables
+
+In these cases helper functions are synthesized by the compiler for use in Block_copy and Block_release, called the copy and dispose helpers. The copy helper emits a call to the C++ const copy constructor for C++ stack based objects and for the rest calls into the runtime support function _Block_object_assign. The dispose helper has a call to the C++ destructor for case 1 and a call into _Block_object_dispose for the rest.
+
+The flags parameter of _Block_object_assign and _Block_object_dispose is set to
+ * BLOCK_FIELD_IS_OBJECT (3), for the case of an Objective-C Object,
+ * BLOCK_FIELD_IS_BLOCK (7), for the case of another Block, and
+ * BLOCK_FIELD_IS_BYREF (8), for the case of a __block variable.
+If the __block variable is marked weak the compiler also or's in BLOCK_FIELD_IS_WEAK (16).
+
+So the Block copy/dispose helpers should only ever generate the four flag values of 3, 7, 8, and 24.
+
+When a __block variable is either a C++ object, an Objective-C object, or another Block then the compiler also generates copy/dispose helper functions. Similarly to the Block copy helper, the "__block" copy helper (formerly and still a.k.a. "byref" copy helper) will do a C++ copy constructor (not a const one though!) and the dispose helper will do the destructor. And similarly the helpers will call into the same two support functions with the same values for objects and Blocks with the additional BLOCK_BYREF_CALLER (128) bit of information supplied.
+
+So the __block copy/dispose helpers will generate flag values of 3 or 7 for objects and Blocks respectively, with BLOCK_FIELD_IS_WEAK (16) or'ed as appropriate and always 128 or'd in, for the following set of possibilities:
+ __block id 128+3
+ __weak block id 128+3+16
+ __block (^Block) 128+7
+ __weak __block (^Block) 128+7+16
+
+The implementation of the two routines would be improved by switch statements enumerating the eight cases.
+
+********************************************************/
+
+/*
+ * When Blocks or Block_byrefs hold objects then their copy routine helpers use this entry point
+ * to do the assignment.
+ */
+void _Block_object_assign(void *destAddr, const void *object, const int flags) {
+ //printf("_Block_object_assign(*%p, %p, %x)\n", destAddr, object, flags);
+ if ((flags & BLOCK_BYREF_CALLER) == BLOCK_BYREF_CALLER) {
+ if ((flags & BLOCK_FIELD_IS_WEAK) == BLOCK_FIELD_IS_WEAK) {
+ _Block_assign_weak(object, destAddr);
+ }
+ else {
+ // do *not* retain or *copy* __block variables whatever they are
+ _Block_assign((void *)object, destAddr);
+ }
+ }
+ else if ((flags & BLOCK_FIELD_IS_BYREF) == BLOCK_FIELD_IS_BYREF) {
+ // copying a __block reference from the stack Block to the heap
+ // flags will indicate if it holds a __weak reference and needs a special isa
+ _Block_byref_assign_copy(destAddr, object, flags);
+ }
+ // (this test must be before next one)
+ else if ((flags & BLOCK_FIELD_IS_BLOCK) == BLOCK_FIELD_IS_BLOCK) {
+ // copying a Block declared variable from the stack Block to the heap
+ _Block_assign(_Block_copy_internal(object, flags), destAddr);
+ }
+ // (this test must be after previous one)
+ else if ((flags & BLOCK_FIELD_IS_OBJECT) == BLOCK_FIELD_IS_OBJECT) {
+ //printf("retaining object at %p\n", object);
+ _Block_retain_object(object);
+ //printf("done retaining object at %p\n", object);
+ _Block_assign((void *)object, destAddr);
+ }
+}
+
+// When Blocks or Block_byrefs hold objects their destroy helper routines call this entry point
+// to help dispose of the contents
+// Used initially only for __attribute__((NSObject)) marked pointers.
+void _Block_object_dispose(const void *object, const int flags) {
+ //printf("_Block_object_dispose(%p, %x)\n", object, flags);
+ if (flags & BLOCK_FIELD_IS_BYREF) {
+ // get rid of the __block data structure held in a Block
+ _Block_byref_release(object);
+ }
+ else if ((flags & (BLOCK_FIELD_IS_BLOCK|BLOCK_BYREF_CALLER)) == BLOCK_FIELD_IS_BLOCK) {
+ // get rid of a referenced Block held by this Block
+ // (ignore __block Block variables, compiler doesn't need to call us)
+ _Block_destroy(object);
+ }
+ else if ((flags & (BLOCK_FIELD_IS_WEAK|BLOCK_FIELD_IS_BLOCK|BLOCK_BYREF_CALLER)) == BLOCK_FIELD_IS_OBJECT) {
+ // get rid of a referenced object held by this Block
+ // (ignore __block object variables, compiler doesn't need to call us)
+ _Block_release_object(object);
+ }
+}
+
+
+/*
+ * Debugging support:
+ */
+#if 0
+#pragma mark Debugging
+#endif /* if 0 */
+
+
+const char *_Block_dump(const void *block) {
+ struct Block_layout *closure = (struct Block_layout *)block;
+ static char buffer[512];
+ char *cp = buffer;
+ if (closure == NULL) {
+ sprintf(cp, "NULL passed to _Block_dump\n");
+ return buffer;
+ }
+ if (! (closure->flags & BLOCK_HAS_DESCRIPTOR)) {
+ printf("Block compiled by obsolete compiler, please recompile source for this Block\n");
+ exit(1);
+ }
+ cp += sprintf(cp, "^%p (new layout) =\n", (void *)closure);
+ if (closure->isa == NULL) {
+ cp += sprintf(cp, "isa: NULL\n");
+ }
+ else if (closure->isa == _NSConcreteStackBlock) {
+ cp += sprintf(cp, "isa: stack Block\n");
+ }
+ else if (closure->isa == _NSConcreteMallocBlock) {
+ cp += sprintf(cp, "isa: malloc heap Block\n");
+ }
+ else if (closure->isa == _NSConcreteAutoBlock) {
+ cp += sprintf(cp, "isa: GC heap Block\n");
+ }
+ else if (closure->isa == _NSConcreteGlobalBlock) {
+ cp += sprintf(cp, "isa: global Block\n");
+ }
+ else if (closure->isa == _NSConcreteFinalizingBlock) {
+ cp += sprintf(cp, "isa: finalizing Block\n");
+ }
+ else {
+ cp += sprintf(cp, "isa?: %p\n", (void *)closure->isa);
+ }
+ cp += sprintf(cp, "flags:");
+ if (closure->flags & BLOCK_HAS_DESCRIPTOR) {
+ cp += sprintf(cp, " HASDESCRIPTOR");
+ }
+ if (closure->flags & BLOCK_NEEDS_FREE) {
+ cp += sprintf(cp, " FREEME");
+ }
+ if (closure->flags & BLOCK_IS_GC) {
+ cp += sprintf(cp, " ISGC");
+ }
+ if (closure->flags & BLOCK_HAS_COPY_DISPOSE) {
+ cp += sprintf(cp, " HASHELP");
+ }
+ if (closure->flags & BLOCK_HAS_CTOR) {
+ cp += sprintf(cp, " HASCTOR");
+ }
+ cp += sprintf(cp, "\nrefcount: %u\n", closure->flags & BLOCK_REFCOUNT_MASK);
+ cp += sprintf(cp, "invoke: %p\n", (void *)(uintptr_t)closure->invoke);
+ {
+ struct Block_descriptor *dp = closure->descriptor;
+ cp += sprintf(cp, "descriptor: %p\n", (void *)dp);
+ cp += sprintf(cp, "descriptor->reserved: %lu\n", dp->reserved);
+ cp += sprintf(cp, "descriptor->size: %lu\n", dp->size);
+
+ if (closure->flags & BLOCK_HAS_COPY_DISPOSE) {
+ cp += sprintf(cp, "descriptor->copy helper: %p\n", (void *)(uintptr_t)dp->copy);
+ cp += sprintf(cp, "descriptor->dispose helper: %p\n", (void *)(uintptr_t)dp->dispose);
+ }
+ }
+ return buffer;
+}
+
+
+const char *_Block_byref_dump(struct Block_byref *src) {
+ static char buffer[256];
+ char *cp = buffer;
+ cp += sprintf(cp, "byref data block %p contents:\n", (void *)src);
+ cp += sprintf(cp, " forwarding: %p\n", (void *)src->forwarding);
+ cp += sprintf(cp, " flags: 0x%x\n", src->flags);
+ cp += sprintf(cp, " size: %d\n", src->size);
+ if (src->flags & BLOCK_HAS_COPY_DISPOSE) {
+ cp += sprintf(cp, " copy helper: %p\n", (void *)(uintptr_t)src->byref_keep);
+ cp += sprintf(cp, " dispose helper: %p\n", (void *)(uintptr_t)src->byref_destroy);
+ }
+ return buffer;
+}
+
diff --git a/contrib/compiler-rt/CREDITS.TXT b/contrib/compiler-rt/CREDITS.TXT
new file mode 100644
index 0000000..8b07b82
--- /dev/null
+++ b/contrib/compiler-rt/CREDITS.TXT
@@ -0,0 +1,21 @@
+This file is a partial list of people who have contributed to the LLVM/CompilerRT
+project. If you have contributed a patch or made some other contribution to
+LLVM/CompilerRT, please submit a patch to this file to add yourself, and it will be
+done!
+
+The list is sorted by surname and formatted to allow easy grepping and
+beautification by scripts. The fields are: name (N), email (E), web-address
+(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
+(S).
+
+N: Craig van Vliet
+E: cvanvliet@auroraux.org
+W: http://www.auroraux.org
+D: Code style and Readability fixes.
+
+N: Edward O'Callaghan
+E: eocallaghan@auroraux.org
+W: http://www.auroraux.org
+D: CMake'ify Compiler-RT build system
+D: Maintain Solaris & AuroraUX ports of Compiler-RT
+
diff --git a/contrib/compiler-rt/LICENSE.TXT b/contrib/compiler-rt/LICENSE.TXT
new file mode 100644
index 0000000..a5e1345
--- /dev/null
+++ b/contrib/compiler-rt/LICENSE.TXT
@@ -0,0 +1,63 @@
+==============================================================================
+LLVM Release License
+==============================================================================
+University of Illinois/NCSA
+Open Source License
+
+Copyright (c) 2003-2009 University of Illinois at Urbana-Champaign.
+All rights reserved.
+
+Developed by:
+
+ LLVM Team
+
+ University of Illinois at Urbana-Champaign
+
+ http://llvm.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal with
+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:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimers.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimers in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the names of the LLVM Team, University of Illinois at
+ Urbana-Champaign, nor the names of its contributors may be used to
+ endorse or promote products derived from this Software without specific
+ prior written permission.
+
+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
+CONTRIBUTORS 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 WITH THE
+SOFTWARE.
+
+==============================================================================
+Copyrights and Licenses for Third Party Software Distributed with LLVM:
+==============================================================================
+The LLVM software contains code written by third parties. Such software will
+have its own individual LICENSE.TXT file in the directory in which it appears.
+This file will describe the copyrights, license, and restrictions which apply
+to that code.
+
+The disclaimer of warranty in the University of Illinois Open Source License
+applies to all code in the LLVM Distribution, and nothing in any of the
+other licenses gives permission to use the names of the LLVM Team or the
+University of Illinois to endorse or promote products derived from this
+Software.
+
+The following pieces of software have additional or alternate copyrights,
+licenses, and/or restrictions:
+
+Program Directory
+------- ---------
diff --git a/contrib/compiler-rt/README.txt b/contrib/compiler-rt/README.txt
new file mode 100644
index 0000000..ab389d2
--- /dev/null
+++ b/contrib/compiler-rt/README.txt
@@ -0,0 +1,330 @@
+Compiler-RT
+================================
+
+This directory and its subdirectories contain source code for the compiler
+support routines.
+
+Compiler-RT is open source software. You may freely distribute it under the
+terms of the license agreement found in LICENSE.txt.
+
+================================
+
+This is a replacement library for libgcc. Each function is contained
+in its own file. Each function has a corresponding unit test under
+test/Unit.
+
+A rudimentary script to test each file is in the file called
+test/Unit/test.
+
+Here is the specification for this library:
+
+http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc
+
+Here is a synopsis of the contents of this library:
+
+typedef int si_int;
+typedef unsigned su_int;
+
+typedef long long di_int;
+typedef unsigned long long du_int;
+
+// Integral bit manipulation
+
+di_int __ashldi3(di_int a, si_int b); // a << b
+ti_int __ashlti3(ti_int a, si_int b); // a << b
+
+di_int __ashrdi3(di_int a, si_int b); // a >> b arithmetic (sign fill)
+ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill)
+di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill)
+ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill)
+
+si_int __clzsi2(si_int a); // count leading zeros
+si_int __clzdi2(di_int a); // count leading zeros
+si_int __clzti2(ti_int a); // count leading zeros
+si_int __ctzsi2(si_int a); // count trailing zeros
+si_int __ctzdi2(di_int a); // count trailing zeros
+si_int __ctzti2(ti_int a); // count trailing zeros
+
+si_int __ffsdi2(di_int a); // find least significant 1 bit
+si_int __ffsti2(ti_int a); // find least significant 1 bit
+
+si_int __paritysi2(si_int a); // bit parity
+si_int __paritydi2(di_int a); // bit parity
+si_int __parityti2(ti_int a); // bit parity
+
+si_int __popcountsi2(si_int a); // bit population
+si_int __popcountdi2(di_int a); // bit population
+si_int __popcountti2(ti_int a); // bit population
+
+uint32_t __bswapsi2(uint32_t a); // a byteswapped, arm only
+uint64_t __bswapdi2(uint64_t a); // a byteswapped, arm only
+
+// Integral arithmetic
+
+di_int __negdi2 (di_int a); // -a
+ti_int __negti2 (ti_int a); // -a
+di_int __muldi3 (di_int a, di_int b); // a * b
+ti_int __multi3 (ti_int a, ti_int b); // a * b
+si_int __divsi3 (si_int a, si_int b); // a / b signed
+di_int __divdi3 (di_int a, di_int b); // a / b signed
+ti_int __divti3 (ti_int a, ti_int b); // a / b signed
+su_int __udivsi3 (su_int n, su_int d); // a / b unsigned
+du_int __udivdi3 (du_int a, du_int b); // a / b unsigned
+tu_int __udivti3 (tu_int a, tu_int b); // a / b unsigned
+si_int __modsi3 (si_int a, si_int b); // a % b signed
+di_int __moddi3 (di_int a, di_int b); // a % b signed
+ti_int __modti3 (ti_int a, ti_int b); // a % b signed
+su_int __umodsi3 (su_int a, su_int b); // a % b unsigned
+du_int __umoddi3 (du_int a, du_int b); // a % b unsigned
+tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned
+du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b
+tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b
+
+// Integral arithmetic with trapping overflow
+
+si_int __absvsi2(si_int a); // abs(a)
+di_int __absvdi2(di_int a); // abs(a)
+ti_int __absvti2(ti_int a); // abs(a)
+
+si_int __negvsi2(si_int a); // -a
+di_int __negvdi2(di_int a); // -a
+ti_int __negvti2(ti_int a); // -a
+
+si_int __addvsi3(si_int a, si_int b); // a + b
+di_int __addvdi3(di_int a, di_int b); // a + b
+ti_int __addvti3(ti_int a, ti_int b); // a + b
+
+si_int __subvsi3(si_int a, si_int b); // a - b
+di_int __subvdi3(di_int a, di_int b); // a - b
+ti_int __subvti3(ti_int a, ti_int b); // a - b
+
+si_int __mulvsi3(si_int a, si_int b); // a * b
+di_int __mulvdi3(di_int a, di_int b); // a * b
+ti_int __mulvti3(ti_int a, ti_int b); // a * b
+
+// Integral comparison: a < b -> 0
+// a == b -> 1
+// a > b -> 2
+
+si_int __cmpdi2 (di_int a, di_int b);
+si_int __cmpti2 (ti_int a, ti_int b);
+si_int __ucmpdi2(du_int a, du_int b);
+si_int __ucmpti2(tu_int a, tu_int b);
+
+// Integral / floating point conversion
+
+di_int __fixsfdi( float a);
+di_int __fixdfdi( double a);
+di_int __fixxfdi(long double a);
+
+ti_int __fixsfti( float a);
+ti_int __fixdfti( double a);
+ti_int __fixxfti(long double a);
+uint64_t __fixtfdi(long double input); // ppc only, doesn't match documentation
+
+su_int __fixunssfsi( float a);
+su_int __fixunsdfsi( double a);
+su_int __fixunsxfsi(long double a);
+
+du_int __fixunssfdi( float a);
+du_int __fixunsdfdi( double a);
+du_int __fixunsxfdi(long double a);
+
+tu_int __fixunssfti( float a);
+tu_int __fixunsdfti( double a);
+tu_int __fixunsxfti(long double a);
+uint64_t __fixunstfdi(long double input); // ppc only
+
+float __floatdisf(di_int a);
+double __floatdidf(di_int a);
+long double __floatdixf(di_int a);
+long double __floatditf(int64_t a); // ppc only
+
+float __floattisf(ti_int a);
+double __floattidf(ti_int a);
+long double __floattixf(ti_int a);
+
+float __floatundisf(du_int a);
+double __floatundidf(du_int a);
+long double __floatundixf(du_int a);
+long double __floatunditf(uint64_t a); // ppc only
+
+float __floatuntisf(tu_int a);
+double __floatuntidf(tu_int a);
+long double __floatuntixf(tu_int a);
+
+// Floating point raised to integer power
+
+float __powisf2( float a, si_int b); // a ^ b
+double __powidf2( double a, si_int b); // a ^ b
+long double __powixf2(long double a, si_int b); // a ^ b
+long double __powitf2(long double a, si_int b); // ppc only, a ^ b
+
+// Complex arithmetic
+
+// (a + ib) * (c + id)
+
+ float _Complex __mulsc3( float a, float b, float c, float d);
+ double _Complex __muldc3(double a, double b, double c, double d);
+long double _Complex __mulxc3(long double a, long double b,
+ long double c, long double d);
+long double _Complex __multc3(long double a, long double b,
+ long double c, long double d); // ppc only
+
+// (a + ib) / (c + id)
+
+ float _Complex __divsc3( float a, float b, float c, float d);
+ double _Complex __divdc3(double a, double b, double c, double d);
+long double _Complex __divxc3(long double a, long double b,
+ long double c, long double d);
+long double _Complex __divtc3(long double a, long double b,
+ long double c, long double d); // ppc only
+
+
+// Runtime support
+
+// __clear_cache() is used to tell process that new instructions have been
+// written to an address range. Necessary on processors that do not have
+// a unified instuction and data cache.
+void __clear_cache(void* start, void* end);
+
+// __enable_execute_stack() is used with nested functions when a trampoline
+// function is written onto the stack and that page range needs to be made
+// executable.
+void __enable_execute_stack(void* addr);
+
+// __gcc_personality_v0() is normally only called by the system unwinder.
+// C code (as opposed to C++) normally does not need a personality function
+// because there are no catch clauses or destructors to be run. But there
+// is a C language extension __attribute__((cleanup(func))) which marks local
+// variables as needing the cleanup function "func" to be run when the
+// variable goes out of scope. That includes when an exception is thrown,
+// so a personality handler is needed.
+_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
+ uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
+ _Unwind_Context_t context);
+
+// for use with some implementations of assert() in <assert.h>
+void __eprintf(const char* format, const char* assertion_expression,
+ const char* line, const char* file);
+
+
+
+// Power PC specific functions
+
+// There is no C interface to the saveFP/restFP functions. They are helper
+// functions called by the prolog and epilog of functions that need to save
+// a number of non-volatile float point registers.
+saveFP
+restFP
+
+// PowerPC has a standard template for trampoline functions. This function
+// generates a custom trampoline function with the specific realFunc
+// and localsPtr values.
+void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
+ const void* realFunc, void* localsPtr);
+
+// adds two 128-bit double-double precision values ( x + y )
+long double __gcc_qadd(long double x, long double y);
+
+// subtracts two 128-bit double-double precision values ( x - y )
+long double __gcc_qsub(long double x, long double y);
+
+// multiples two 128-bit double-double precision values ( x * y )
+long double __gcc_qmul(long double x, long double y);
+
+// divides two 128-bit double-double precision values ( x / y )
+long double __gcc_qdiv(long double a, long double b);
+
+
+// ARM specific functions
+
+// There is no C interface to the switch* functions. These helper functions
+// are only needed by Thumb1 code for efficient switch table generation.
+switch16
+switch32
+switch8
+switchu8
+
+// There is no C interface to the *_vfp_d8_d15_regs functions. There are
+// called in the prolog and epilog of Thumb1 functions. When the C++ ABI use
+// SJLJ for exceptions, each function with a catch clause or destuctors needs
+// to save and restore all registers in it prolog and epliog. But there is
+// no way to access vector and high float registers from thumb1 code, so the
+// compiler must add call outs to these helper functions in the prolog and
+// epilog.
+restore_vfp_d8_d15_regs
+save_vfp_d8_d15_regs
+
+
+// Note: long ago ARM processors did not have floating point hardware support.
+// Floating point was done in software and floating point parameters were
+// passed in integer registers. When hardware support was added for floating
+// point, new *vfp functions were added to do the same operations but with
+// floating point parameters in floating point registers.
+
+// Undocumented functions
+
+float __addsf3vfp(float a, float b); // Appears to return a + b
+double __adddf3vfp(double a, double b); // Appears to return a + b
+float __divsf3vfp(float a, float b); // Appears to return a / b
+double __divdf3vfp(double a, double b); // Appears to return a / b
+int __eqsf2vfp(float a, float b); // Appears to return one
+ // iff a == b and neither is NaN.
+int __eqdf2vfp(double a, double b); // Appears to return one
+ // iff a == b and neither is NaN.
+double __extendsfdf2vfp(float a); // Appears to convert from
+ // float to double.
+int __fixdfsivfp(double a); // Appears to convert from
+ // double to int.
+int __fixsfsivfp(float a); // Appears to convert from
+ // float to int.
+unsigned int __fixunssfsivfp(float a); // Appears to convert from
+ // float to unsigned int.
+unsigned int __fixunsdfsivfp(double a); // Appears to convert from
+ // double to unsigned int.
+double __floatsidfvfp(int a); // Appears to convert from
+ // int to double.
+float __floatsisfvfp(int a); // Appears to convert from
+ // int to float.
+double __floatunssidfvfp(unsigned int a); // Appears to convert from
+ // unisgned int to double.
+float __floatunssisfvfp(unsigned int a); // Appears to convert from
+ // unisgned int to float.
+int __gedf2vfp(double a, double b); // Appears to return __gedf2
+ // (a >= b)
+int __gesf2vfp(float a, float b); // Appears to return __gesf2
+ // (a >= b)
+int __gtdf2vfp(double a, double b); // Appears to return __gtdf2
+ // (a > b)
+int __gtsf2vfp(float a, float b); // Appears to return __gtsf2
+ // (a > b)
+int __ledf2vfp(double a, double b); // Appears to return __ledf2
+ // (a <= b)
+int __lesf2vfp(float a, float b); // Appears to return __lesf2
+ // (a <= b)
+int __ltdf2vfp(double a, double b); // Appears to return __ltdf2
+ // (a < b)
+int __ltsf2vfp(float a, float b); // Appears to return __ltsf2
+ // (a < b)
+double __muldf3vfp(double a, double b); // Appears to return a * b
+float __mulsf3vfp(float a, float b); // Appears to return a * b
+int __nedf2vfp(double a, double b); // Appears to return __nedf2
+ // (a != b)
+double __negdf2vfp(double a); // Appears to return -a
+float __negsf2vfp(float a); // Appears to return -a
+float __negsf2vfp(float a); // Appears to return -a
+double __subdf3vfp(double a, double b); // Appears to return a - b
+float __subsf3vfp(float a, float b); // Appears to return a - b
+float __truncdfsf2vfp(double a); // Appears to convert from
+ // double to float.
+int __unorddf2vfp(double a, double b); // Appears to return __unorddf2
+int __unordsf2vfp(float a, float b); // Appears to return __unordsf2
+
+
+Preconditions are listed for each function at the definition when there are any.
+Any preconditions reflect the specification at
+http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc.
+
+Assumptions are listed in "int_lib.h", and in individual files. Where possible
+assumptions are checked at compile time.
diff --git a/contrib/compiler-rt/lib/absvdi2.c b/contrib/compiler-rt/lib/absvdi2.c
new file mode 100644
index 0000000..919afd1
--- /dev/null
+++ b/contrib/compiler-rt/lib/absvdi2.c
@@ -0,0 +1,30 @@
+/*===-- absvdi2.c - Implement __absvdi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===
+ *
+ * This file implements __absvdi2 for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: absolute value */
+
+/* Effects: aborts if abs(x) < 0 */
+
+di_int
+__absvdi2(di_int a)
+{
+ const int N = (int)(sizeof(di_int) * CHAR_BIT);
+ if (a == ((di_int)1 << (N-1)))
+ compilerrt_abort();
+ const di_int t = a >> (N - 1);
+ return (a ^ t) - t;
+}
diff --git a/contrib/compiler-rt/lib/absvsi2.c b/contrib/compiler-rt/lib/absvsi2.c
new file mode 100644
index 0000000..a2c8e3f
--- /dev/null
+++ b/contrib/compiler-rt/lib/absvsi2.c
@@ -0,0 +1,30 @@
+/* ===-- absvsi2.c - Implement __absvsi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __absvsi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: absolute value */
+
+/* Effects: aborts if abs(x) < 0 */
+
+si_int
+__absvsi2(si_int a)
+{
+ const int N = (int)(sizeof(si_int) * CHAR_BIT);
+ if (a == (1 << (N-1)))
+ compilerrt_abort();
+ const si_int t = a >> (N - 1);
+ return (a ^ t) - t;
+}
diff --git a/contrib/compiler-rt/lib/absvti2.c b/contrib/compiler-rt/lib/absvti2.c
new file mode 100644
index 0000000..0978122
--- /dev/null
+++ b/contrib/compiler-rt/lib/absvti2.c
@@ -0,0 +1,34 @@
+/* ===-- absvti2.c - Implement __absvdi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __absvti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: absolute value */
+
+/* Effects: aborts if abs(x) < 0 */
+
+ti_int
+__absvti2(ti_int a)
+{
+ const int N = (int)(sizeof(ti_int) * CHAR_BIT);
+ if (a == ((ti_int)1 << (N-1)))
+ compilerrt_abort();
+ const ti_int s = a >> (N - 1);
+ return (a ^ s) - s;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/adddf3.c b/contrib/compiler-rt/lib/adddf3.c
new file mode 100644
index 0000000..1ec43dc
--- /dev/null
+++ b/contrib/compiler-rt/lib/adddf3.c
@@ -0,0 +1,154 @@
+//===-- lib/adddf3.c - Double-precision addition and subtraction --*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements double-precision soft-float addition and subtraction
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __adddf3(fp_t a, fp_t b) {
+
+ rep_t aRep = toRep(a);
+ rep_t bRep = toRep(b);
+ const rep_t aAbs = aRep & absMask;
+ const rep_t bAbs = bRep & absMask;
+
+ // Detect if a or b is zero, infinity, or NaN.
+ if (aAbs - 1U >= infRep - 1U || bAbs - 1U >= infRep - 1U) {
+
+ // NaN + anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything + NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // +/-infinity + -/+infinity = qNaN
+ if ((toRep(a) ^ toRep(b)) == signBit) return fromRep(qnanRep);
+ // +/-infinity + anything remaining = +/- infinity
+ else return a;
+ }
+
+ // anything remaining + +/-infinity = +/-infinity
+ if (bAbs == infRep) return b;
+
+ // zero + anything = anything
+ if (!aAbs) {
+ // but we need to get the sign right for zero + zero
+ if (!bAbs) return fromRep(toRep(a) & toRep(b));
+ else return b;
+ }
+
+ // anything + zero = anything
+ if (!bAbs) return a;
+ }
+
+ // Swap a and b if necessary so that a has the larger absolute value.
+ if (bAbs > aAbs) {
+ const rep_t temp = aRep;
+ aRep = bRep;
+ bRep = temp;
+ }
+
+ // Extract the exponent and significand from the (possibly swapped) a and b.
+ int aExponent = aRep >> significandBits & maxExponent;
+ int bExponent = bRep >> significandBits & maxExponent;
+ rep_t aSignificand = aRep & significandMask;
+ rep_t bSignificand = bRep & significandMask;
+
+ // Normalize any denormals, and adjust the exponent accordingly.
+ if (aExponent == 0) aExponent = normalize(&aSignificand);
+ if (bExponent == 0) bExponent = normalize(&bSignificand);
+
+ // The sign of the result is the sign of the larger operand, a. If they
+ // have opposite signs, we are performing a subtraction; otherwise addition.
+ const rep_t resultSign = aRep & signBit;
+ const bool subtraction = (aRep ^ bRep) & signBit;
+
+ // Shift the significands to give us round, guard and sticky, and or in the
+ // implicit significand bit. (If we fell through from the denormal path it
+ // was already set by normalize( ), but setting it twice won't hurt
+ // anything.)
+ aSignificand = (aSignificand | implicitBit) << 3;
+ bSignificand = (bSignificand | implicitBit) << 3;
+
+ // Shift the significand of b by the difference in exponents, with a sticky
+ // bottom bit to get rounding correct.
+ const int align = aExponent - bExponent;
+ if (align) {
+ if (align < typeWidth) {
+ const bool sticky = bSignificand << (typeWidth - align);
+ bSignificand = bSignificand >> align | sticky;
+ } else {
+ bSignificand = 1; // sticky; b is known to be non-zero.
+ }
+ }
+
+ if (subtraction) {
+ aSignificand -= bSignificand;
+
+ // If a == -b, return +zero.
+ if (aSignificand == 0) return fromRep(0);
+
+ // If partial cancellation occured, we need to left-shift the result
+ // and adjust the exponent:
+ if (aSignificand < implicitBit << 3) {
+ const int shift = rep_clz(aSignificand) - rep_clz(implicitBit << 3);
+ aSignificand <<= shift;
+ aExponent -= shift;
+ }
+ }
+
+ else /* addition */ {
+ aSignificand += bSignificand;
+
+ // If the addition carried up, we need to right-shift the result and
+ // adjust the exponent:
+ if (aSignificand & implicitBit << 4) {
+ const bool sticky = aSignificand & 1;
+ aSignificand = aSignificand >> 1 | sticky;
+ aExponent += 1;
+ }
+ }
+
+ // If we have overflowed the type, return +/- infinity:
+ if (aExponent >= maxExponent) return fromRep(infRep | resultSign);
+
+ if (aExponent <= 0) {
+ // Result is denormal before rounding; the exponent is zero and we
+ // need to shift the significand.
+ const int shift = 1 - aExponent;
+ const bool sticky = aSignificand << (typeWidth - shift);
+ aSignificand = aSignificand >> shift | sticky;
+ aExponent = 0;
+ }
+
+ // Low three bits are round, guard, and sticky.
+ const int roundGuardSticky = aSignificand & 0x7;
+
+ // Shift the significand into place, and mask off the implicit bit.
+ rep_t result = aSignificand >> 3 & significandMask;
+
+ // Insert the exponent and sign.
+ result |= (rep_t)aExponent << significandBits;
+ result |= resultSign;
+
+ // Final rounding. The result may overflow to infinity, but that is the
+ // correct result in that case.
+ if (roundGuardSticky > 0x4) result++;
+ if (roundGuardSticky == 0x4) result += result & 1;
+ return fromRep(result);
+}
+
+// Subtraction; flip the sign bit of b and add.
+fp_t __subdf3(fp_t a, fp_t b) {
+ return __adddf3(a, fromRep(toRep(b) ^ signBit));
+}
diff --git a/contrib/compiler-rt/lib/addsf3.c b/contrib/compiler-rt/lib/addsf3.c
new file mode 100644
index 0000000..fec14e8
--- /dev/null
+++ b/contrib/compiler-rt/lib/addsf3.c
@@ -0,0 +1,164 @@
+//===-- lib/addsf3.c - Single-precision addition and subtraction --*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements single-precision soft-float addition and subtraction
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __addsf3(fp_t a, fp_t b) {
+
+ rep_t aRep = toRep(a);
+ rep_t bRep = toRep(b);
+ const rep_t aAbs = aRep & absMask;
+ const rep_t bAbs = bRep & absMask;
+
+ // Detect if a or b is zero, infinity, or NaN.
+ if (aAbs - 1U >= infRep - 1U || bAbs - 1U >= infRep - 1U) {
+
+ // NaN + anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything + NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // +/-infinity + -/+infinity = qNaN
+ if ((toRep(a) ^ toRep(b)) == signBit) return fromRep(qnanRep);
+ // +/-infinity + anything remaining = +/- infinity
+ else return a;
+ }
+
+ // anything remaining + +/-infinity = +/-infinity
+ if (bAbs == infRep) return b;
+
+ // zero + anything = anything
+ if (!aAbs) {
+ // but we need to get the sign right for zero + zero
+ if (!bAbs) return fromRep(toRep(a) & toRep(b));
+ else return b;
+ }
+
+ // anything + zero = anything
+ if (!bAbs) return a;
+ }
+
+ // Swap a and b if necessary so that a has the larger absolute value.
+ if (bAbs > aAbs) {
+ const rep_t temp = aRep;
+ aRep = bRep;
+ bRep = temp;
+ }
+
+ // Extract the exponent and significand from the (possibly swapped) a and b.
+ int aExponent = aRep >> significandBits & maxExponent;
+ int bExponent = bRep >> significandBits & maxExponent;
+ rep_t aSignificand = aRep & significandMask;
+ rep_t bSignificand = bRep & significandMask;
+
+ // Normalize any denormals, and adjust the exponent accordingly.
+ if (aExponent == 0) aExponent = normalize(&aSignificand);
+ if (bExponent == 0) bExponent = normalize(&bSignificand);
+
+ // The sign of the result is the sign of the larger operand, a. If they
+ // have opposite signs, we are performing a subtraction; otherwise addition.
+ const rep_t resultSign = aRep & signBit;
+ const bool subtraction = (aRep ^ bRep) & signBit;
+
+ // Shift the significands to give us round, guard and sticky, and or in the
+ // implicit significand bit. (If we fell through from the denormal path it
+ // was already set by normalize( ), but setting it twice won't hurt
+ // anything.)
+ aSignificand = (aSignificand | implicitBit) << 3;
+ bSignificand = (bSignificand | implicitBit) << 3;
+
+ // Shift the significand of b by the difference in exponents, with a sticky
+ // bottom bit to get rounding correct.
+ const int align = aExponent - bExponent;
+ if (align) {
+ if (align < typeWidth) {
+ const bool sticky = bSignificand << (typeWidth - align);
+ bSignificand = bSignificand >> align | sticky;
+ } else {
+ bSignificand = 1; // sticky; b is known to be non-zero.
+ }
+ }
+
+ if (subtraction) {
+ aSignificand -= bSignificand;
+
+ // If a == -b, return +zero.
+ if (aSignificand == 0) return fromRep(0);
+
+ // If partial cancellation occured, we need to left-shift the result
+ // and adjust the exponent:
+ if (aSignificand < implicitBit << 3) {
+ const int shift = rep_clz(aSignificand) - rep_clz(implicitBit << 3);
+ aSignificand <<= shift;
+ aExponent -= shift;
+ }
+ }
+
+ else /* addition */ {
+ aSignificand += bSignificand;
+
+ // If the addition carried up, we need to right-shift the result and
+ // adjust the exponent:
+ if (aSignificand & implicitBit << 4) {
+ const bool sticky = aSignificand & 1;
+ aSignificand = aSignificand >> 1 | sticky;
+ aExponent += 1;
+ }
+ }
+
+ // If we have overflowed the type, return +/- infinity:
+ if (aExponent >= maxExponent) return fromRep(infRep | resultSign);
+
+ if (aExponent <= 0) {
+ // Result is denormal before rounding; the exponent is zero and we
+ // need to shift the significand.
+ const int shift = 1 - aExponent;
+ const bool sticky = aSignificand << (typeWidth - shift);
+ aSignificand = aSignificand >> shift | sticky;
+ aExponent = 0;
+ }
+
+ // Low three bits are round, guard, and sticky.
+ const int roundGuardSticky = aSignificand & 0x7;
+
+ // Shift the significand into place, and mask off the implicit bit.
+ rep_t result = aSignificand >> 3 & significandMask;
+
+ // Insert the exponent and sign.
+ result |= (rep_t)aExponent << significandBits;
+ result |= resultSign;
+
+ // Final rounding. The result may overflow to infinity, but that is the
+ // correct result in that case.
+ if (roundGuardSticky > 0x4) result++;
+ if (roundGuardSticky == 0x4) result += result & 1;
+ return fromRep(result);
+}
+
+// Subtraction; flip the sign bit of b and add.
+fp_t __subsf3(fp_t a, fp_t b) {
+ return __addsf3(a, fromRep(toRep(b) ^ signBit));
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/contrib/compiler-rt/lib/addvdi3.c b/contrib/compiler-rt/lib/addvdi3.c
new file mode 100644
index 0000000..53ab102
--- /dev/null
+++ b/contrib/compiler-rt/lib/addvdi3.c
@@ -0,0 +1,37 @@
+/* ===-- addvdi3.c - Implement __addvdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __addvdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a + b */
+
+/* Effects: aborts if a + b overflows */
+
+di_int
+__addvdi3(di_int a, di_int b)
+{
+ di_int s = a + b;
+ if (b >= 0)
+ {
+ if (s < a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s >= a)
+ compilerrt_abort();
+ }
+ return s;
+}
diff --git a/contrib/compiler-rt/lib/addvsi3.c b/contrib/compiler-rt/lib/addvsi3.c
new file mode 100644
index 0000000..22cd315
--- /dev/null
+++ b/contrib/compiler-rt/lib/addvsi3.c
@@ -0,0 +1,37 @@
+/* ===-- addvsi3.c - Implement __addvsi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __addvsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a + b */
+
+/* Effects: aborts if a + b overflows */
+
+si_int
+__addvsi3(si_int a, si_int b)
+{
+ si_int s = a + b;
+ if (b >= 0)
+ {
+ if (s < a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s >= a)
+ compilerrt_abort();
+ }
+ return s;
+}
diff --git a/contrib/compiler-rt/lib/addvti3.c b/contrib/compiler-rt/lib/addvti3.c
new file mode 100644
index 0000000..3df1a74
--- /dev/null
+++ b/contrib/compiler-rt/lib/addvti3.c
@@ -0,0 +1,41 @@
+/* ===-- addvti3.c - Implement __addvti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __addvti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a + b */
+
+/* Effects: aborts if a + b overflows */
+
+ti_int
+__addvti3(ti_int a, ti_int b)
+{
+ ti_int s = a + b;
+ if (b >= 0)
+ {
+ if (s < a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s >= a)
+ compilerrt_abort();
+ }
+ return s;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/apple_versioning.c b/contrib/compiler-rt/lib/apple_versioning.c
new file mode 100644
index 0000000..0360026
--- /dev/null
+++ b/contrib/compiler-rt/lib/apple_versioning.c
@@ -0,0 +1,150 @@
+/* ===-- apple_versioning.c - Adds versioning symbols for ld ---------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+
+
+#if __APPLE__
+ #if __arm__
+ #define NOT_HERE_BEFORE_10_6(sym)
+ #elif __ppc__
+ #define NOT_HERE_BEFORE_10_6(sym) \
+ extern const char sym##_tmp3 __asm("$ld$hide$os10.3$_" #sym ); \
+ __attribute__((visibility("default"))) const char sym##_tmp3 = 0; \
+ extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
+ __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
+ extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \
+ __attribute__((visibility("default"))) const char sym##_tmp5 = 0;
+ #else
+ #define NOT_HERE_BEFORE_10_6(sym) \
+ extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
+ __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
+ extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \
+ __attribute__((visibility("default"))) const char sym##_tmp5 = 0;
+ #endif /* __ppc__ */
+
+
+/* Symbols in libSystem.dylib in 10.6 and later,
+ * but are in libgcc_s.dylib in earlier versions
+ */
+
+NOT_HERE_BEFORE_10_6(__absvdi2)
+NOT_HERE_BEFORE_10_6(__absvsi2)
+NOT_HERE_BEFORE_10_6(__absvti2)
+NOT_HERE_BEFORE_10_6(__addvdi3)
+NOT_HERE_BEFORE_10_6(__addvsi3)
+NOT_HERE_BEFORE_10_6(__addvti3)
+NOT_HERE_BEFORE_10_6(__ashldi3)
+NOT_HERE_BEFORE_10_6(__ashlti3)
+NOT_HERE_BEFORE_10_6(__ashrdi3)
+NOT_HERE_BEFORE_10_6(__ashrti3)
+NOT_HERE_BEFORE_10_6(__clear_cache)
+NOT_HERE_BEFORE_10_6(__clzdi2)
+NOT_HERE_BEFORE_10_6(__clzsi2)
+NOT_HERE_BEFORE_10_6(__clzti2)
+NOT_HERE_BEFORE_10_6(__cmpdi2)
+NOT_HERE_BEFORE_10_6(__cmpti2)
+NOT_HERE_BEFORE_10_6(__ctzdi2)
+NOT_HERE_BEFORE_10_6(__ctzsi2)
+NOT_HERE_BEFORE_10_6(__ctzti2)
+NOT_HERE_BEFORE_10_6(__divdc3)
+NOT_HERE_BEFORE_10_6(__divdi3)
+NOT_HERE_BEFORE_10_6(__divsc3)
+NOT_HERE_BEFORE_10_6(__divtc3)
+NOT_HERE_BEFORE_10_6(__divti3)
+NOT_HERE_BEFORE_10_6(__divxc3)
+NOT_HERE_BEFORE_10_6(__enable_execute_stack)
+NOT_HERE_BEFORE_10_6(__ffsdi2)
+NOT_HERE_BEFORE_10_6(__ffsti2)
+NOT_HERE_BEFORE_10_6(__fixdfdi)
+NOT_HERE_BEFORE_10_6(__fixdfti)
+NOT_HERE_BEFORE_10_6(__fixsfdi)
+NOT_HERE_BEFORE_10_6(__fixsfti)
+NOT_HERE_BEFORE_10_6(__fixtfdi)
+NOT_HERE_BEFORE_10_6(__fixunsdfdi)
+NOT_HERE_BEFORE_10_6(__fixunsdfsi)
+NOT_HERE_BEFORE_10_6(__fixunsdfti)
+NOT_HERE_BEFORE_10_6(__fixunssfdi)
+NOT_HERE_BEFORE_10_6(__fixunssfsi)
+NOT_HERE_BEFORE_10_6(__fixunssfti)
+NOT_HERE_BEFORE_10_6(__fixunstfdi)
+NOT_HERE_BEFORE_10_6(__fixunsxfdi)
+NOT_HERE_BEFORE_10_6(__fixunsxfsi)
+NOT_HERE_BEFORE_10_6(__fixunsxfti)
+NOT_HERE_BEFORE_10_6(__fixxfdi)
+NOT_HERE_BEFORE_10_6(__fixxfti)
+NOT_HERE_BEFORE_10_6(__floatdidf)
+NOT_HERE_BEFORE_10_6(__floatdisf)
+NOT_HERE_BEFORE_10_6(__floatditf)
+NOT_HERE_BEFORE_10_6(__floatdixf)
+NOT_HERE_BEFORE_10_6(__floattidf)
+NOT_HERE_BEFORE_10_6(__floattisf)
+NOT_HERE_BEFORE_10_6(__floattixf)
+NOT_HERE_BEFORE_10_6(__floatundidf)
+NOT_HERE_BEFORE_10_6(__floatundisf)
+NOT_HERE_BEFORE_10_6(__floatunditf)
+NOT_HERE_BEFORE_10_6(__floatundixf)
+NOT_HERE_BEFORE_10_6(__floatuntidf)
+NOT_HERE_BEFORE_10_6(__floatuntisf)
+NOT_HERE_BEFORE_10_6(__floatuntixf)
+NOT_HERE_BEFORE_10_6(__gcc_personality_v0)
+NOT_HERE_BEFORE_10_6(__lshrdi3)
+NOT_HERE_BEFORE_10_6(__lshrti3)
+NOT_HERE_BEFORE_10_6(__moddi3)
+NOT_HERE_BEFORE_10_6(__modti3)
+NOT_HERE_BEFORE_10_6(__muldc3)
+NOT_HERE_BEFORE_10_6(__muldi3)
+NOT_HERE_BEFORE_10_6(__mulsc3)
+NOT_HERE_BEFORE_10_6(__multc3)
+NOT_HERE_BEFORE_10_6(__multi3)
+NOT_HERE_BEFORE_10_6(__mulvdi3)
+NOT_HERE_BEFORE_10_6(__mulvsi3)
+NOT_HERE_BEFORE_10_6(__mulvti3)
+NOT_HERE_BEFORE_10_6(__mulxc3)
+NOT_HERE_BEFORE_10_6(__negdi2)
+NOT_HERE_BEFORE_10_6(__negti2)
+NOT_HERE_BEFORE_10_6(__negvdi2)
+NOT_HERE_BEFORE_10_6(__negvsi2)
+NOT_HERE_BEFORE_10_6(__negvti2)
+NOT_HERE_BEFORE_10_6(__paritydi2)
+NOT_HERE_BEFORE_10_6(__paritysi2)
+NOT_HERE_BEFORE_10_6(__parityti2)
+NOT_HERE_BEFORE_10_6(__popcountdi2)
+NOT_HERE_BEFORE_10_6(__popcountsi2)
+NOT_HERE_BEFORE_10_6(__popcountti2)
+NOT_HERE_BEFORE_10_6(__powidf2)
+NOT_HERE_BEFORE_10_6(__powisf2)
+NOT_HERE_BEFORE_10_6(__powitf2)
+NOT_HERE_BEFORE_10_6(__powixf2)
+NOT_HERE_BEFORE_10_6(__subvdi3)
+NOT_HERE_BEFORE_10_6(__subvsi3)
+NOT_HERE_BEFORE_10_6(__subvti3)
+NOT_HERE_BEFORE_10_6(__ucmpdi2)
+NOT_HERE_BEFORE_10_6(__ucmpti2)
+NOT_HERE_BEFORE_10_6(__udivdi3)
+NOT_HERE_BEFORE_10_6(__udivmoddi4)
+NOT_HERE_BEFORE_10_6(__udivmodti4)
+NOT_HERE_BEFORE_10_6(__udivti3)
+NOT_HERE_BEFORE_10_6(__umoddi3)
+NOT_HERE_BEFORE_10_6(__umodti3)
+
+
+#if __ppc__
+NOT_HERE_BEFORE_10_6(__gcc_qadd)
+NOT_HERE_BEFORE_10_6(__gcc_qdiv)
+NOT_HERE_BEFORE_10_6(__gcc_qmul)
+NOT_HERE_BEFORE_10_6(__gcc_qsub)
+NOT_HERE_BEFORE_10_6(__trampoline_setup)
+#endif /* __ppc__ */
+
+#else /* !__APPLE__ */
+
+extern int avoid_empty_file;
+
+#endif /* !__APPLE__*/
diff --git a/contrib/compiler-rt/lib/arm/adddf3vfp.S b/contrib/compiler-rt/lib/arm/adddf3vfp.S
new file mode 100644
index 0000000..5e705e3
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/adddf3vfp.S
@@ -0,0 +1,24 @@
+//===-- adddf3vfp.S - Implement adddf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// double __adddf3vfp(double a, double b) { return a + b; }
+//
+// Adds two double precision floating point numbers using the Darwin
+// calling convention where double arguments are passsed in GPR pairs
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__adddf3vfp)
+ fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6
+ fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7
+ faddd d6, d6, d7
+ fmrrd r0, r1, d6 // move result back to r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/addsf3vfp.S b/contrib/compiler-rt/lib/arm/addsf3vfp.S
new file mode 100644
index 0000000..36d509c
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/addsf3vfp.S
@@ -0,0 +1,24 @@
+//===-- addsf3vfp.S - Implement addsf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __addsf3vfp(float a, float b);
+//
+// Adds two single precision floating point numbers using the Darwin
+// calling convention where single arguments are passsed in GPRs
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__addsf3vfp)
+ fmsr s14, r0 // move first param from r0 into float register
+ fmsr s15, r1 // move second param from r1 into float register
+ fadds s14, s14, s15
+ fmrs r0, s14 // move result back to r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/bswapdi2.S b/contrib/compiler-rt/lib/arm/bswapdi2.S
new file mode 100644
index 0000000..d3ca33a
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/bswapdi2.S
@@ -0,0 +1,36 @@
+//===------- bswapdi2 - Implement bswapdi2 --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern uint64_t __bswapdi2(uint64_t);
+//
+// Reverse all the bytes in a 64-bit integer.
+//
+.align 2
+DEFINE_COMPILERRT_FUNCTION(__bswapdi2)
+#if __ARM_ARCH_5TEJ__ || __ARM_ARCH_4T__
+ // before armv6 does not have "rev" instruction
+ // r2 = rev(r0)
+ eor r2, r0, r0, ror #16
+ bic r2, r2, #0xff0000
+ mov r2, r2, lsr #8
+ eor r2, r2, r0, ror #8
+ // r0 = rev(r1)
+ eor r0, r1, r1, ror #16
+ bic r0, r0, #0xff0000
+ mov r0, r0, lsr #8
+ eor r0, r0, r1, ror #8
+#else
+ rev r2, r0 // r2 = rev(r0)
+ rev r0, r1 // r0 = rev(r1)
+#endif
+ mov r1, r2 // r1 = r2 = rev(r0)
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/bswapsi2.S b/contrib/compiler-rt/lib/arm/bswapsi2.S
new file mode 100644
index 0000000..0a0c073
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/bswapsi2.S
@@ -0,0 +1,28 @@
+//===------- bswapsi2 - Implement bswapsi2 --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern uint32_t __bswapsi2(uint32_t);
+//
+// Reverse all the bytes in a 32-bit integer.
+//
+.align 2
+DEFINE_COMPILERRT_FUNCTION(__bswapsi2)
+#if __ARM_ARCH_5TEJ__ || __ARM_ARCH_4T__
+ // before armv6 does not have "rev" instruction
+ eor r1, r0, r0, ror #16
+ bic r1, r1, #0xff0000
+ mov r1, r1, lsr #8
+ eor r0, r1, r0, ror #8
+#else
+ rev r0, r0
+#endif
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/comparesf2.S b/contrib/compiler-rt/lib/arm/comparesf2.S
new file mode 100644
index 0000000..f21e0bcd
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/comparesf2.S
@@ -0,0 +1,130 @@
+//===-- comparesf2.S - Implement single-precision soft-float comparisons --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the following soft-fp_t comparison routines:
+//
+// __eqsf2 __gesf2 __unordsf2
+// __lesf2 __gtsf2
+// __ltsf2
+// __nesf2
+//
+// The semantics of the routines grouped in each column are identical, so there
+// is a single implementation for each, with multiple names.
+//
+// The routines behave as follows:
+//
+// __lesf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// 1 if either a or b is NaN
+//
+// __gesf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// -1 if either a or b is NaN
+//
+// __unordsf2(a,b) returns 0 if both a and b are numbers
+// 1 if either a or b is NaN
+//
+// Note that __lesf2( ) and __gesf2( ) are identical except in their handling of
+// NaN values.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+.syntax unified
+
+.align 2
+DEFINE_COMPILERRT_FUNCTION(__eqsf2)
+DEFINE_COMPILERRT_FUNCTION(__lesf2)
+DEFINE_COMPILERRT_FUNCTION(__ltsf2)
+DEFINE_COMPILERRT_FUNCTION(__nesf2)
+ // Make copies of a and b with the sign bit shifted off the top. These will
+ // be used to detect zeros and NaNs.
+ mov r2, r0, lsl #1
+ mov r3, r1, lsl #1
+
+ // We do the comparison in three stages (ignoring NaN values for the time
+ // being). First, we orr the absolute values of a and b; this sets the Z
+ // flag if both a and b are zero (of either sign). The shift of r3 doesn't
+ // effect this at all, but it *does* make sure that the C flag is clear for
+ // the subsequent operations.
+ orrs r12, r2, r3, lsr #1
+
+ // Next, we check if a and b have the same or different signs. If they have
+ // opposite signs, this eor will set the N flag.
+ eorsne r12, r0, r1
+
+ // If a and b are equal (either both zeros or bit identical; again, we're
+ // ignoring NaNs for now), this subtract will zero out r0. If they have the
+ // same sign, the flags are updated as they would be for a comparison of the
+ // absolute values of a and b.
+ subspl r0, r2, r3
+
+ // If a is smaller in magnitude than b and both have the same sign, place
+ // the negation of the sign of b in r0. Thus, if both are negative and
+ // a > b, this sets r0 to 0; if both are positive and a < b, this sets
+ // r0 to -1.
+ //
+ // This is also done if a and b have opposite signs and are not both zero,
+ // because in that case the subtract was not performed and the C flag is
+ // still clear from the shift argument in orrs; if a is positive and b
+ // negative, this places 0 in r0; if a is negative and b positive, -1 is
+ // placed in r0.
+ mvnlo r0, r1, asr #31
+
+ // If a is greater in magnitude than b and both have the same sign, place
+ // the sign of b in r0. Thus, if both are negative and a < b, -1 is placed
+ // in r0, which is the desired result. Conversely, if both are positive
+ // and a > b, zero is placed in r0.
+ movhi r0, r1, asr #31
+
+ // If you've been keeping track, at this point r0 contains -1 if a < b and
+ // 0 if a >= b. All that remains to be done is to set it to 1 if a > b.
+ // If a == b, then the Z flag is set, so we can get the correct final value
+ // into r0 by simply or'ing with 1 if Z is clear.
+ orrne r0, r0, #1
+
+ // Finally, we need to deal with NaNs. If either argument is NaN, replace
+ // the value in r0 with 1.
+ cmp r2, #0xff000000
+ cmpls r3, #0xff000000
+ movhi r0, #1
+ bx lr
+
+.align 2
+DEFINE_COMPILERRT_FUNCTION(__gesf2)
+DEFINE_COMPILERRT_FUNCTION(__gtsf2)
+ // Identical to the preceeding except in that we return -1 for NaN values.
+ // Given that the two paths share so much code, one might be tempted to
+ // unify them; however, the extra code needed to do so makes the code size
+ // to performance tradeoff very hard to justify for such small functions.
+ mov r2, r0, lsl #1
+ mov r3, r1, lsl #1
+ orrs r12, r2, r3, lsr #1
+ eorsne r12, r0, r1
+ subspl r0, r2, r3
+ mvnlo r0, r1, asr #31
+ movhi r0, r1, asr #31
+ orrne r0, r0, #1
+ cmp r2, #0xff000000
+ cmpls r3, #0xff000000
+ movhi r0, #-1
+ bx lr
+
+.align 2
+DEFINE_COMPILERRT_FUNCTION(__unordsf2)
+ // Return 1 for NaN values, 0 otherwise.
+ mov r2, r0, lsl #1
+ mov r3, r1, lsl #1
+ mov r0, #0
+ cmp r2, #0xff000000
+ cmpls r3, #0xff000000
+ movhi r0, #1
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/divdf3vfp.S b/contrib/compiler-rt/lib/arm/divdf3vfp.S
new file mode 100644
index 0000000..e43baa3
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/divdf3vfp.S
@@ -0,0 +1,24 @@
+//===-- divdf3vfp.S - Implement divdf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __divdf3vfp(double a, double b);
+//
+// Divides two double precision floating point numbers using the Darwin
+// calling convention where double arguments are passsed in GPR pairs
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__divdf3vfp)
+ fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6
+ fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7
+ fdivd d5, d6, d7
+ fmrrd r0, r1, d5 // move result back to r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/divsf3vfp.S b/contrib/compiler-rt/lib/arm/divsf3vfp.S
new file mode 100644
index 0000000..d96c930
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/divsf3vfp.S
@@ -0,0 +1,24 @@
+//===-- divsf3vfp.S - Implement divsf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __divsf3vfp(float a, float b);
+//
+// Divides two single precision floating point numbers using the Darwin
+// calling convention where single arguments are passsed like 32-bit ints.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__divsf3vfp)
+ fmsr s14, r0 // move first param from r0 into float register
+ fmsr s15, r1 // move second param from r1 into float register
+ fdivs s13, s14, s15
+ fmrs r0, s13 // move result back to r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/eqdf2vfp.S b/contrib/compiler-rt/lib/arm/eqdf2vfp.S
new file mode 100644
index 0000000..d4384ec
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/eqdf2vfp.S
@@ -0,0 +1,27 @@
+//===-- eqdf2vfp.S - Implement eqdf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __eqdf2vfp(double a, double b);
+//
+// Returns one iff a == b and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__eqdf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ moveq r0, #1 // set result register to 1 if equal
+ movne r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/eqsf2vfp.S b/contrib/compiler-rt/lib/arm/eqsf2vfp.S
new file mode 100644
index 0000000..07355a3
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/eqsf2vfp.S
@@ -0,0 +1,28 @@
+//===-- eqsf2vfp.S - Implement eqsf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __eqsf2vfp(float a, float b);
+//
+// Returns one iff a == b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__eqsf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ moveq r0, #1 // set result register to 1 if equal
+ movne r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S b/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S
new file mode 100644
index 0000000..4343a7e
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/extendsfdf2vfp.S
@@ -0,0 +1,24 @@
+//===-- extendsfdf2vfp.S - Implement extendsfdf2vfp -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __extendsfdf2vfp(float a);
+//
+// Converts single precision float to double precision result.
+// Uses Darwin calling convention where a single precision parameter is
+// passed in a GPR and a double precision result is returned in R0/R1 pair.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__extendsfdf2vfp)
+ fmsr s15, r0 // load float register from R0
+ fcvtds d7, s15 // convert single to double
+ fmrrd r0, r1, d7 // return result in r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/fixdfsivfp.S b/contrib/compiler-rt/lib/arm/fixdfsivfp.S
new file mode 100644
index 0000000..30458cc
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/fixdfsivfp.S
@@ -0,0 +1,24 @@
+//===-- fixdfsivfp.S - Implement fixdfsivfp -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __fixdfsivfp(double a);
+//
+// Converts double precision float to a 32-bit int rounding towards zero.
+// Uses Darwin calling convention where a double precision parameter is
+// passed in GPR register pair.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__fixdfsivfp)
+ fmdrr d7, r0, r1 // load double register from R0/R1
+ ftosizd s15, d7 // convert double to 32-bit int into s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/fixsfsivfp.S b/contrib/compiler-rt/lib/arm/fixsfsivfp.S
new file mode 100644
index 0000000..ce6f18e
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/fixsfsivfp.S
@@ -0,0 +1,24 @@
+//===-- fixsfsivfp.S - Implement fixsfsivfp -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __fixsfsivfp(float a);
+//
+// Converts single precision float to a 32-bit int rounding towards zero.
+// Uses Darwin calling convention where a single precision parameter is
+// passed in a GPR..
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__fixsfsivfp)
+ fmsr s15, r0 // load float register from R0
+ ftosizs s15, s15 // convert single to 32-bit int into s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S b/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S
new file mode 100644
index 0000000..7e766c0
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/fixunsdfsivfp.S
@@ -0,0 +1,25 @@
+//===-- fixunsdfsivfp.S - Implement fixunsdfsivfp -------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern unsigned int __fixunsdfsivfp(double a);
+//
+// Converts double precision float to a 32-bit unsigned int rounding towards
+// zero. All negative values become zero.
+// Uses Darwin calling convention where a double precision parameter is
+// passed in GPR register pair.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__fixunsdfsivfp)
+ fmdrr d7, r0, r1 // load double register from R0/R1
+ ftouizd s15, d7 // convert double to 32-bit int into s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/fixunssfsivfp.S b/contrib/compiler-rt/lib/arm/fixunssfsivfp.S
new file mode 100644
index 0000000..ba2344f
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/fixunssfsivfp.S
@@ -0,0 +1,25 @@
+//===-- fixunssfsivfp.S - Implement fixunssfsivfp -------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern unsigned int __fixunssfsivfp(float a);
+//
+// Converts single precision float to a 32-bit unsigned int rounding towards
+// zero. All negative values become zero.
+// Uses Darwin calling convention where a single precision parameter is
+// passed in a GPR..
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__fixunssfsivfp)
+ fmsr s15, r0 // load float register from R0
+ ftouizs s15, s15 // convert single to 32-bit unsigned into s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/floatsidfvfp.S b/contrib/compiler-rt/lib/arm/floatsidfvfp.S
new file mode 100644
index 0000000..5ed4ace
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/floatsidfvfp.S
@@ -0,0 +1,24 @@
+//===-- floatsidfvfp.S - Implement floatsidfvfp ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __floatsidfvfp(int a);
+//
+// Converts a 32-bit int to a double precision float.
+// Uses Darwin calling convention where a double precision result is
+// return in GPR register pair.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__floatsidfvfp)
+ fmsr s15, r0 // move int to float register s15
+ fsitod d7, s15 // convert 32-bit int in s15 to double in d7
+ fmrrd r0, r1, d7 // move d7 to result register pair r0/r1
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/floatsisfvfp.S b/contrib/compiler-rt/lib/arm/floatsisfvfp.S
new file mode 100644
index 0000000..0114c78
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/floatsisfvfp.S
@@ -0,0 +1,24 @@
+//===-- floatsisfvfp.S - Implement floatsisfvfp ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __floatsisfvfp(int a);
+//
+// Converts single precision float to a 32-bit int rounding towards zero.
+// Uses Darwin calling convention where a single precision result is
+// return in a GPR..
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__floatsisfvfp)
+ fmsr s15, r0 // move int to float register s15
+ fsitos s15, s15 // convert 32-bit int in s15 to float in s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/floatunssidfvfp.S b/contrib/compiler-rt/lib/arm/floatunssidfvfp.S
new file mode 100644
index 0000000..d1bfe3a
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/floatunssidfvfp.S
@@ -0,0 +1,24 @@
+//===-- floatunssidfvfp.S - Implement floatunssidfvfp ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __floatunssidfvfp(unsigned int a);
+//
+// Converts a 32-bit int to a double precision float.
+// Uses Darwin calling convention where a double precision result is
+// return in GPR register pair.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__floatunssidfvfp)
+ fmsr s15, r0 // move int to float register s15
+ fuitod d7, s15 // convert 32-bit int in s15 to double in d7
+ fmrrd r0, r1, d7 // move d7 to result register pair r0/r1
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/floatunssisfvfp.S b/contrib/compiler-rt/lib/arm/floatunssisfvfp.S
new file mode 100644
index 0000000..0b73577
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/floatunssisfvfp.S
@@ -0,0 +1,24 @@
+//===-- floatunssisfvfp.S - Implement floatunssisfvfp ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __floatunssisfvfp(unsigned int a);
+//
+// Converts single precision float to a 32-bit int rounding towards zero.
+// Uses Darwin calling convention where a single precision result is
+// return in a GPR..
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__floatunssisfvfp)
+ fmsr s15, r0 // move int to float register s15
+ fuitos s15, s15 // convert 32-bit int in s15 to float in s15
+ fmrs r0, s15 // move s15 to result register
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/gedf2vfp.S b/contrib/compiler-rt/lib/arm/gedf2vfp.S
new file mode 100644
index 0000000..6ab856f
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/gedf2vfp.S
@@ -0,0 +1,27 @@
+//===-- gedf2vfp.S - Implement gedf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __gedf2vfp(double a, double b);
+//
+// Returns one iff a >= b and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__gedf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movge r0, #1 // set result register to 1 if greater than or equal
+ movlt r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/gesf2vfp.S b/contrib/compiler-rt/lib/arm/gesf2vfp.S
new file mode 100644
index 0000000..b00d821
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/gesf2vfp.S
@@ -0,0 +1,28 @@
+//===-- gesf2vfp.S - Implement gesf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __gesf2vfp(float a, float b);
+//
+// Returns one iff a >= b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__gesf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movge r0, #1 // set result register to 1 if greater than or equal
+ movlt r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/gtdf2vfp.S b/contrib/compiler-rt/lib/arm/gtdf2vfp.S
new file mode 100644
index 0000000..65594c7
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/gtdf2vfp.S
@@ -0,0 +1,27 @@
+//===-- gtdf2vfp.S - Implement gtdf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __gtdf2vfp(double a, double b);
+//
+// Returns one iff a > b and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__gtdf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movgt r0, #1 // set result register to 1 if equal
+ movle r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/gtsf2vfp.S b/contrib/compiler-rt/lib/arm/gtsf2vfp.S
new file mode 100644
index 0000000..53ef2a0
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/gtsf2vfp.S
@@ -0,0 +1,28 @@
+//===-- gtsf2vfp.S - Implement gtsf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __gtsf2vfp(float a, float b);
+//
+// Returns one iff a > b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__gtsf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movgt r0, #1 // set result register to 1 if equal
+ movle r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/ledf2vfp.S b/contrib/compiler-rt/lib/arm/ledf2vfp.S
new file mode 100644
index 0000000..327a7d5
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/ledf2vfp.S
@@ -0,0 +1,27 @@
+//===-- ledf2vfp.S - Implement ledf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __ledf2vfp(double a, double b);
+//
+// Returns one iff a <= b and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__ledf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movls r0, #1 // set result register to 1 if equal
+ movhi r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/lesf2vfp.S b/contrib/compiler-rt/lib/arm/lesf2vfp.S
new file mode 100644
index 0000000..b7e05da
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/lesf2vfp.S
@@ -0,0 +1,28 @@
+//===-- lesf2vfp.S - Implement lesf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __lesf2vfp(float a, float b);
+//
+// Returns one iff a <= b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__lesf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movls r0, #1 // set result register to 1 if equal
+ movhi r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/ltdf2vfp.S b/contrib/compiler-rt/lib/arm/ltdf2vfp.S
new file mode 100644
index 0000000..55dfd80
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/ltdf2vfp.S
@@ -0,0 +1,27 @@
+//===-- ltdf2vfp.S - Implement ltdf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __ltdf2vfp(double a, double b);
+//
+// Returns one iff a < b and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__ltdf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movmi r0, #1 // set result register to 1 if equal
+ movpl r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/ltsf2vfp.S b/contrib/compiler-rt/lib/arm/ltsf2vfp.S
new file mode 100644
index 0000000..3816a71
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/ltsf2vfp.S
@@ -0,0 +1,28 @@
+//===-- ltsf2vfp.S - Implement ltsf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __ltsf2vfp(float a, float b);
+//
+// Returns one iff a < b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__ltsf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movmi r0, #1 // set result register to 1 if equal
+ movpl r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/modsi3.S b/contrib/compiler-rt/lib/arm/modsi3.S
new file mode 100644
index 0000000..64a3afd
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/modsi3.S
@@ -0,0 +1,36 @@
+//===-------- modsi3.S - Implement modsi3 ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int32_t __modsi3(int32_t a, int32_t b);
+//
+// Returns the remainder when dividing two 32-bit signed integers.
+// Conceptually, the function is: { return a - (a / b) * b; }
+// But if you write that in C, llvm compiles it to a call to __modsi3...
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__modsi3)
+ push {r4, r5, r7, lr}
+ add r7, sp, #8 // set stack frame
+ mov r5, r0 // save a
+ mov r4, r1 // save b
+ bl ___divsi3 // compute a/b
+#if __ARM_ARCH_7A__
+ mls r0, r4, r0, r5 // mulitple result * b and subtract from a
+#else
+ // before armv7, does not have "mls" instruction
+ mul r3, r0, r4 // multiple result * b
+ sub r0, r5, r3 // a - result
+#endif
+ pop {r4, r5, r7, pc}
+
+
+
diff --git a/contrib/compiler-rt/lib/arm/muldf3vfp.S b/contrib/compiler-rt/lib/arm/muldf3vfp.S
new file mode 100644
index 0000000..cb503d3
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/muldf3vfp.S
@@ -0,0 +1,24 @@
+//===-- muldf3vfp.S - Implement muldf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __muldf3vfp(double a, double b);
+//
+// Multiplies two double precision floating point numbers using the Darwin
+// calling convention where double arguments are passsed in GPR pairs
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__muldf3vfp)
+ fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6
+ fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7
+ fmuld d6, d6, d7
+ fmrrd r0, r1, d6 // move result back to r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/mulsf3vfp.S b/contrib/compiler-rt/lib/arm/mulsf3vfp.S
new file mode 100644
index 0000000..49b4d1d
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/mulsf3vfp.S
@@ -0,0 +1,24 @@
+//===-- mulsf3vfp.S - Implement mulsf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __mulsf3vfp(float a, float b);
+//
+// Multiplies two single precision floating point numbers using the Darwin
+// calling convention where single arguments are passsed like 32-bit ints.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__mulsf3vfp)
+ fmsr s14, r0 // move first param from r0 into float register
+ fmsr s15, r1 // move second param from r1 into float register
+ fmuls s13, s14, s15
+ fmrs r0, s13 // move result back to r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/nedf2vfp.S b/contrib/compiler-rt/lib/arm/nedf2vfp.S
new file mode 100644
index 0000000..813864e
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/nedf2vfp.S
@@ -0,0 +1,27 @@
+//===-- nedf2vfp.S - Implement nedf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __nedf2vfp(double a, double b);
+//
+// Returns zero if a and b are unequal and neither is NaN.
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__nedf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movne r0, #1 // set result register to 0 if unequal
+ moveq r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/negdf2vfp.S b/contrib/compiler-rt/lib/arm/negdf2vfp.S
new file mode 100644
index 0000000..80139754
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/negdf2vfp.S
@@ -0,0 +1,21 @@
+//===-- negdf2vfp.S - Implement negdf2vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __negdf2vfp(double a, double b);
+//
+// Returns the negation a double precision floating point numbers using the
+// Darwin calling convention where double arguments are passsed in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__negdf2vfp)
+ eor r1, r1, #-2147483648 // flip sign bit on double in r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/negsf2vfp.S b/contrib/compiler-rt/lib/arm/negsf2vfp.S
new file mode 100644
index 0000000..243c086
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/negsf2vfp.S
@@ -0,0 +1,21 @@
+//===-- negsf2vfp.S - Implement negsf2vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __negsf2vfp(float a);
+//
+// Returns the negation of a single precision floating point numbers using the
+// Darwin calling convention where single arguments are passsed like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__negsf2vfp)
+ eor r0, r0, #-2147483648 // flip sign bit on float in r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/nesf2vfp.S b/contrib/compiler-rt/lib/arm/nesf2vfp.S
new file mode 100644
index 0000000..d470afa
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/nesf2vfp.S
@@ -0,0 +1,28 @@
+//===-- nesf2vfp.S - Implement nesf2vfp -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __nesf2vfp(float a, float b);
+//
+// Returns one iff a != b and neither is NaN.
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__nesf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movne r0, #1 // set result register to 1 if unequal
+ moveq r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/arm/restore_vfp_d8_d15_regs.S b/contrib/compiler-rt/lib/arm/restore_vfp_d8_d15_regs.S
new file mode 100644
index 0000000..25404cd
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/restore_vfp_d8_d15_regs.S
@@ -0,0 +1,37 @@
+//===-- save_restore_regs.S - Implement save/restore* ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling C++ functions that need to handle thrown exceptions the
+// compiler is required to save all registers and call __Unwind_SjLj_Register
+// in the function prolog. But when compiling for thumb1, there are
+// no instructions to access the floating point registers, so the
+// compiler needs to add a call to the helper function _save_vfp_d8_d15_regs
+// written in ARM to save the float registers. In the epilog, the compiler
+// must also add a call to __restore_vfp_d8_d15_regs to restore those registers.
+//
+
+ .text
+ .syntax unified
+
+//
+// Restore registers d8-d15 from stack
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__restore_vfp_d8_d15_regs)
+ vldmia sp!, {d8-d15} // pop registers d8-d15 off stack
+ bx lr // return to prolog
+
+
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
diff --git a/contrib/compiler-rt/lib/arm/save_vfp_d8_d15_regs.S b/contrib/compiler-rt/lib/arm/save_vfp_d8_d15_regs.S
new file mode 100644
index 0000000..92de61b
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/save_vfp_d8_d15_regs.S
@@ -0,0 +1,35 @@
+//===-- save_restore_regs.S - Implement save/restore* ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling C++ functions that need to handle thrown exceptions the
+// compiler is required to save all registers and call __Unwind_SjLj_Register
+// in the function prolog. But when compiling for thumb1, there are
+// no instructions to access the floating point registers, so the
+// compiler needs to add a call to the helper function _save_vfp_d8_d15_regs
+// written in ARM to save the float registers. In the epilog, the compiler
+// must also add a call to __restore_vfp_d8_d15_regs to restore those registers.
+//
+
+ .text
+ .syntax unified
+
+//
+// Save registers d8-d15 onto stack
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__save_vfp_d8_d15_regs)
+ vstmdb sp!, {d8-d15} // push registers d8-d15 onto stack
+ bx lr // return to prolog
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
diff --git a/contrib/compiler-rt/lib/arm/subdf3vfp.S b/contrib/compiler-rt/lib/arm/subdf3vfp.S
new file mode 100644
index 0000000..8841600
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/subdf3vfp.S
@@ -0,0 +1,24 @@
+//===-- subdf3vfp.S - Implement subdf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern double __subdf3vfp(double a, double b);
+//
+// Returns difference between two double precision floating point numbers using
+// the Darwin calling convention where double arguments are passsed in GPR pairs
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__subdf3vfp)
+ fmdrr d6, r0, r1 // move first param from r0/r1 pair into d6
+ fmdrr d7, r2, r3 // move second param from r2/r3 pair into d7
+ fsubd d6, d6, d7
+ fmrrd r0, r1, d6 // move result back to r0/r1 pair
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/subsf3vfp.S b/contrib/compiler-rt/lib/arm/subsf3vfp.S
new file mode 100644
index 0000000..4ead9c23
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/subsf3vfp.S
@@ -0,0 +1,25 @@
+//===-- subsf3vfp.S - Implement subsf3vfp ---------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __subsf3vfp(float a, float b);
+//
+// Returns the difference between two single precision floating point numbers
+// using the Darwin calling convention where single arguments are passsed
+// like 32-bit ints.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__subsf3vfp)
+ fmsr s14, r0 // move first param from r0 into float register
+ fmsr s15, r1 // move second param from r1 into float register
+ fsubs s14, s14, s15
+ fmrs r0, s14 // move result back to r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/switch16.S b/contrib/compiler-rt/lib/arm/switch16.S
new file mode 100644
index 0000000..05c7b98
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/switch16.S
@@ -0,0 +1,44 @@
+//===-- switch.S - Implement switch* --------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling switch statements in thumb mode, the compiler
+// can use these __switch* helper functions The compiler emits a blx to
+// the __switch* function followed by a table of displacements for each
+// case statement. On entry, R0 is the index into the table. The __switch*
+// function uses the return address in lr to find the start of the table.
+// The first entry in the table is the count of the entries in the table.
+// It then uses R0 to index into the table and get the displacement of the
+// address to jump to. If R0 is greater than the size of the table, it jumps
+// to the last entry in the table. Each displacement in the table is actually
+// the distance from lr to the label, thus making the tables PIC.
+
+
+ .text
+ .syntax unified
+
+//
+// The table contains signed 2-byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch16)
+ ldrh ip, [lr, #-1] // get first 16-bit word in table
+ cmp r0, ip // compare with index
+ add r0, lr, r0, lsl #1 // compute address of element in table
+ ldrshcc r0, [r0, #1] // load 16-bit element if r0 is in range
+ add ip, lr, ip, lsl #1 // compute address of last element in table
+ ldrshhs r0, [ip, #1] // load 16-bit element if r0 out of range
+ add ip, lr, r0, lsl #1 // compute label = lr + element*2
+ bx ip // jump to computed label
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
diff --git a/contrib/compiler-rt/lib/arm/switch32.S b/contrib/compiler-rt/lib/arm/switch32.S
new file mode 100644
index 0000000..a127cb7
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/switch32.S
@@ -0,0 +1,46 @@
+//===-- switch.S - Implement switch* --------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling switch statements in thumb mode, the compiler
+// can use these __switch* helper functions The compiler emits a blx to
+// the __switch* function followed by a table of displacements for each
+// case statement. On entry, R0 is the index into the table. The __switch*
+// function uses the return address in lr to find the start of the table.
+// The first entry in the table is the count of the entries in the table.
+// It then uses R0 to index into the table and get the displacement of the
+// address to jump to. If R0 is greater than the size of the table, it jumps
+// to the last entry in the table. Each displacement in the table is actually
+// the distance from lr to the label, thus making the tables PIC.
+
+
+ .text
+ .syntax unified
+
+//
+// The table contains signed 4-byte sized elements which are the distance
+// from lr to the target label.
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch32)
+ ldr ip, [lr, #-1] // get first 32-bit word in table
+ cmp r0, ip // compare with index
+ add r0, lr, r0, lsl #2 // compute address of element in table
+ ldrcc r0, [r0, #3] // load 32-bit element if r0 is in range
+ add ip, lr, ip, lsl #2 // compute address of last element in table
+ ldrcs r0, [ip, #3] // load 32-bit element if r0 out of range
+ add ip, lr, r0 // compute label = lr + element
+ bx ip // jump to computed label
+
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
diff --git a/contrib/compiler-rt/lib/arm/switch8.S b/contrib/compiler-rt/lib/arm/switch8.S
new file mode 100644
index 0000000..d05f6ac
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/switch8.S
@@ -0,0 +1,43 @@
+//===-- switch.S - Implement switch* --------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling switch statements in thumb mode, the compiler
+// can use these __switch* helper functions The compiler emits a blx to
+// the __switch* function followed by a table of displacements for each
+// case statement. On entry, R0 is the index into the table. The __switch*
+// function uses the return address in lr to find the start of the table.
+// The first entry in the table is the count of the entries in the table.
+// It then uses R0 to index into the table and get the displacement of the
+// address to jump to. If R0 is greater than the size of the table, it jumps
+// to the last entry in the table. Each displacement in the table is actually
+// the distance from lr to the label, thus making the tables PIC.
+
+
+ .text
+ .syntax unified
+
+//
+// The table contains signed byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch8)
+ ldrb ip, [lr, #-1] // get first byte in table
+ cmp r0, ip // signed compare with index
+ ldrsbcc r0, [lr, r0] // get indexed byte out of table
+ ldrsbhs r0, [lr, ip] // if out of range, use last entry in table
+ add ip, lr, r0, lsl #1 // compute label = lr + element*2
+ bx ip // jump to computed label
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
diff --git a/contrib/compiler-rt/lib/arm/switchu8.S b/contrib/compiler-rt/lib/arm/switchu8.S
new file mode 100644
index 0000000..faffddb
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/switchu8.S
@@ -0,0 +1,43 @@
+//===-- switch.S - Implement switch* --------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling switch statements in thumb mode, the compiler
+// can use these __switch* helper functions The compiler emits a blx to
+// the __switch* function followed by a table of displacements for each
+// case statement. On entry, R0 is the index into the table. The __switch*
+// function uses the return address in lr to find the start of the table.
+// The first entry in the table is the count of the entries in the table.
+// It then uses R0 to index into the table and get the displacement of the
+// address to jump to. If R0 is greater than the size of the table, it jumps
+// to the last entry in the table. Each displacement in the table is actually
+// the distance from lr to the label, thus making the tables PIC.
+
+
+ .text
+ .syntax unified
+
+//
+// The table contains unsigned byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switchu8)
+ ldrb ip, [lr, #-1] // get first byte in table
+ cmp r0, ip // compare with index
+ ldrbcc r0, [lr, r0] // get indexed byte out of table
+ ldrbhs r0, [lr, ip] // if out of range, use last entry in table
+ add ip, lr, r0, lsl #1 // compute label = lr + element*2
+ bx ip // jump to computed label
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
diff --git a/contrib/compiler-rt/lib/arm/sync_synchronize.S b/contrib/compiler-rt/lib/arm/sync_synchronize.S
new file mode 100644
index 0000000..76fdab1
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/sync_synchronize.S
@@ -0,0 +1,34 @@
+//===-- sync_synchronize - Implement memory barrier * ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// When compiling a use of the gcc built-in __sync_synchronize() in thumb1 mode
+// the compiler may emit a call to __sync_synchronize.
+// On Darwin the implementation jumps to an OS supplied function named
+// OSMemoryBarrier
+//
+
+ .text
+ .syntax unified
+
+#if __APPLE__
+
+ .align 2
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(__sync_synchronize)
+ stmfd sp!, {r7, lr}
+ add r7, sp, #0
+ bl _OSMemoryBarrier
+ ldmfd sp!, {r7, pc}
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+
+#endif
diff --git a/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S b/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S
new file mode 100644
index 0000000..5725e25
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/truncdfsf2vfp.S
@@ -0,0 +1,24 @@
+//===-- truncdfsf2vfp.S - Implement truncdfsf2vfp -------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern float __truncdfsf2vfp(double a);
+//
+// Converts double precision float to signle precision result.
+// Uses Darwin calling convention where a double precision parameter is
+// passed in a R0/R1 pair and a signle precision result is returned in R0.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__truncdfsf2vfp)
+ fmdrr d7, r0, r1 // load double from r0/r1 pair
+ fcvtsd s15, d7 // convert double to single (trucate precision)
+ fmrs r0, s15 // return result in r0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/unorddf2vfp.S b/contrib/compiler-rt/lib/arm/unorddf2vfp.S
new file mode 100644
index 0000000..de00b07
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/unorddf2vfp.S
@@ -0,0 +1,27 @@
+//===-- unorddf2vfp.S - Implement unorddf2vfp ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __unorddf2vfp(double a, double b);
+//
+// Returns one iff a or b is NaN
+// Uses Darwin calling convention where double precision arguments are passsed
+// like in GPR pairs.
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__unorddf2vfp)
+ fmdrr d6, r0, r1 // load r0/r1 pair in double register
+ fmdrr d7, r2, r3 // load r2/r3 pair in double register
+ fcmpd d6, d7
+ fmstat
+ movvs r0, #1 // set result register to 1 if "overflow" (any NaNs)
+ movvc r0, #0
+ bx lr
diff --git a/contrib/compiler-rt/lib/arm/unordsf2vfp.S b/contrib/compiler-rt/lib/arm/unordsf2vfp.S
new file mode 100644
index 0000000..ab291a8
--- /dev/null
+++ b/contrib/compiler-rt/lib/arm/unordsf2vfp.S
@@ -0,0 +1,28 @@
+//===-- unordsf2vfp.S - Implement unordsf2vfp -----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// extern int __unordsf2vfp(float a, float b);
+//
+// Returns one iff a or b is NaN
+// Uses Darwin calling convention where single precision arguments are passsed
+// like 32-bit ints
+//
+ .align 2
+DEFINE_COMPILERRT_FUNCTION(__unordsf2vfp)
+ fmsr s14, r0 // move from GPR 0 to float register
+ fmsr s15, r1 // move from GPR 1 to float register
+ fcmps s14, s15
+ fmstat
+ movvs r0, #1 // set result register to 1 if "overflow" (any NaNs)
+ movvc r0, #0
+ bx lr
+
diff --git a/contrib/compiler-rt/lib/ashldi3.c b/contrib/compiler-rt/lib/ashldi3.c
new file mode 100644
index 0000000..993f71c
--- /dev/null
+++ b/contrib/compiler-rt/lib/ashldi3.c
@@ -0,0 +1,41 @@
+/* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ashldi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a << b */
+
+/* Precondition: 0 <= b < bits_in_dword */
+
+di_int
+__ashldi3(di_int a, si_int b)
+{
+ const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
+ dwords input;
+ dwords result;
+ input.all = a;
+ if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
+ {
+ result.s.low = 0;
+ result.s.high = input.s.low << (b - bits_in_word);
+ }
+ else /* 0 <= b < bits_in_word */
+ {
+ if (b == 0)
+ return a;
+ result.s.low = input.s.low << b;
+ result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_word - b));
+ }
+ return result.all;
+}
diff --git a/contrib/compiler-rt/lib/ashlti3.c b/contrib/compiler-rt/lib/ashlti3.c
new file mode 100644
index 0000000..317de66
--- /dev/null
+++ b/contrib/compiler-rt/lib/ashlti3.c
@@ -0,0 +1,45 @@
+/* ===-- ashlti3.c - Implement __ashlti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ashlti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: a << b */
+
+/* Precondition: 0 <= b < bits_in_tword */
+
+ti_int
+__ashlti3(ti_int a, si_int b)
+{
+ const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
+ twords input;
+ twords result;
+ input.all = a;
+ if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
+ {
+ result.s.low = 0;
+ result.s.high = input.s.low << (b - bits_in_dword);
+ }
+ else /* 0 <= b < bits_in_dword */
+ {
+ if (b == 0)
+ return a;
+ result.s.low = input.s.low << b;
+ result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_dword - b));
+ }
+ return result.all;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/ashrdi3.c b/contrib/compiler-rt/lib/ashrdi3.c
new file mode 100644
index 0000000..8e27a11
--- /dev/null
+++ b/contrib/compiler-rt/lib/ashrdi3.c
@@ -0,0 +1,42 @@
+/*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ashrdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: arithmetic a >> b */
+
+/* Precondition: 0 <= b < bits_in_dword */
+
+di_int
+__ashrdi3(di_int a, si_int b)
+{
+ const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
+ dwords input;
+ dwords result;
+ input.all = a;
+ if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
+ {
+ /* result.s.high = input.s.high < 0 ? -1 : 0 */
+ result.s.high = input.s.high >> (bits_in_word - 1);
+ result.s.low = input.s.high >> (b - bits_in_word);
+ }
+ else /* 0 <= b < bits_in_word */
+ {
+ if (b == 0)
+ return a;
+ result.s.high = input.s.high >> b;
+ result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
+ }
+ return result.all;
+}
diff --git a/contrib/compiler-rt/lib/ashrti3.c b/contrib/compiler-rt/lib/ashrti3.c
new file mode 100644
index 0000000..4eab247
--- /dev/null
+++ b/contrib/compiler-rt/lib/ashrti3.c
@@ -0,0 +1,46 @@
+/* ===-- ashrti3.c - Implement __ashrti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ashrti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: arithmetic a >> b */
+
+/* Precondition: 0 <= b < bits_in_tword */
+
+ti_int
+__ashrti3(ti_int a, si_int b)
+{
+ const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
+ twords input;
+ twords result;
+ input.all = a;
+ if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
+ {
+ /* result.s.high = input.s.high < 0 ? -1 : 0 */
+ result.s.high = input.s.high >> (bits_in_dword - 1);
+ result.s.low = input.s.high >> (b - bits_in_dword);
+ }
+ else /* 0 <= b < bits_in_dword */
+ {
+ if (b == 0)
+ return a;
+ result.s.high = input.s.high >> b;
+ result.s.low = (input.s.high << (bits_in_dword - b)) | (input.s.low >> b);
+ }
+ return result.all;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/assembly.h b/contrib/compiler-rt/lib/assembly.h
new file mode 100644
index 0000000..c124e19
--- /dev/null
+++ b/contrib/compiler-rt/lib/assembly.h
@@ -0,0 +1,54 @@
+/* ===-- assembly.h - compiler-rt assembler support macros -----------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file defines macros for use in compiler-rt assembler source.
+ * This file is not part of the interface of this library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#ifndef COMPILERRT_ASSEMBLY_H
+#define COMPILERRT_ASSEMBLY_H
+
+#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
+#define SEPARATOR @
+#else
+#define SEPARATOR ;
+#endif
+
+/* We can't use __USER_LABEL_PREFIX__ here, it isn't possible to concatenate the
+ *values* of two macros. This is quite brittle, though. */
+#if defined(__APPLE__)
+#define SYMBOL_NAME(name) _##name
+#else
+#define SYMBOL_NAME(name) name
+#endif
+
+#ifdef VISIBILITY_HIDDEN
+#define DEFINE_COMPILERRT_FUNCTION(name) \
+ .globl SYMBOL_NAME(name) SEPARATOR \
+ .hidden SYMBOL_NAME(name) SEPARATOR \
+ SYMBOL_NAME(name):
+#else
+#define DEFINE_COMPILERRT_FUNCTION(name) \
+ .globl SYMBOL_NAME(name) SEPARATOR \
+ SYMBOL_NAME(name):
+#endif
+
+#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
+ .globl SYMBOL_NAME(name) SEPARATOR \
+ .hidden SYMBOL_NAME(name) SEPARATOR \
+ SYMBOL_NAME(name):
+
+#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
+ .globl name SEPARATOR \
+ .hidden name SEPARATOR \
+ name:
+
+#endif /* COMPILERRT_ASSEMBLY_H */
diff --git a/contrib/compiler-rt/lib/clear_cache.c b/contrib/compiler-rt/lib/clear_cache.c
new file mode 100644
index 0000000..43db37a
--- /dev/null
+++ b/contrib/compiler-rt/lib/clear_cache.c
@@ -0,0 +1,41 @@
+/* ===-- clear_cache.c - Implement __clear_cache ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+#if __APPLE__
+ #include <libkern/OSCacheControl.h>
+#endif
+
+/*
+ * The compiler generates calls to __clear_cache() when creating
+ * trampoline functions on the stack for use with nested functions.
+ * It is expected to invalidate the instruction cache for the
+ * specified range.
+ */
+
+void __clear_cache(void* start, void* end)
+{
+#if __i386__ || __x86_64__
+/*
+ * Intel processors have a unified instruction and data cache
+ * so there is nothing to do
+ */
+#else
+ #if __APPLE__
+ /* On Darwin, sys_icache_invalidate() provides this functionality */
+ sys_icache_invalidate(start, end-start);
+ #else
+ compilerrt_abort();
+ #endif
+#endif
+}
+
diff --git a/contrib/compiler-rt/lib/clzdi2.c b/contrib/compiler-rt/lib/clzdi2.c
new file mode 100644
index 0000000..ea95396
--- /dev/null
+++ b/contrib/compiler-rt/lib/clzdi2.c
@@ -0,0 +1,29 @@
+/* ===-- clzdi2.c - Implement __clzdi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __clzdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: the number of leading 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__clzdi2(di_int a)
+{
+ dwords x;
+ x.all = a;
+ const si_int f = -(x.s.high == 0);
+ return __builtin_clz((x.s.high & ~f) | (x.s.low & f)) +
+ (f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
+}
diff --git a/contrib/compiler-rt/lib/clzsi2.c b/contrib/compiler-rt/lib/clzsi2.c
new file mode 100644
index 0000000..7e14af2
--- /dev/null
+++ b/contrib/compiler-rt/lib/clzsi2.c
@@ -0,0 +1,53 @@
+/* ===-- clzsi2.c - Implement __clzsi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __clzsi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: the number of leading 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__clzsi2(si_int a)
+{
+ su_int x = (su_int)a;
+ si_int t = ((x & 0xFFFF0000) == 0) << 4; /* if (x is small) t = 16 else 0 */
+ x >>= 16 - t; /* x = [0 - 0xFFFF] */
+ su_int r = t; /* r = [0, 16] */
+ /* return r + clz(x) */
+ t = ((x & 0xFF00) == 0) << 3;
+ x >>= 8 - t; /* x = [0 - 0xFF] */
+ r += t; /* r = [0, 8, 16, 24] */
+ /* return r + clz(x) */
+ t = ((x & 0xF0) == 0) << 2;
+ x >>= 4 - t; /* x = [0 - 0xF] */
+ r += t; /* r = [0, 4, 8, 12, 16, 20, 24, 28] */
+ /* return r + clz(x) */
+ t = ((x & 0xC) == 0) << 1;
+ x >>= 2 - t; /* x = [0 - 3] */
+ r += t; /* r = [0 - 30] and is even */
+ /* return r + clz(x) */
+/* switch (x)
+ * {
+ * case 0:
+ * return r + 2;
+ * case 1:
+ * return r + 1;
+ * case 2:
+ * case 3:
+ * return r;
+ * }
+ */
+ return r + ((2 - x) & -((x & 2) == 0));
+}
diff --git a/contrib/compiler-rt/lib/clzti2.c b/contrib/compiler-rt/lib/clzti2.c
new file mode 100644
index 0000000..805688f
--- /dev/null
+++ b/contrib/compiler-rt/lib/clzti2.c
@@ -0,0 +1,33 @@
+/* ===-- clzti2.c - Implement __clzti2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __clzti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: the number of leading 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__clzti2(ti_int a)
+{
+ twords x;
+ x.all = a;
+ const di_int f = -(x.s.high == 0);
+ return __builtin_clzll((x.s.high & ~f) | (x.s.low & f)) +
+ ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/cmpdi2.c b/contrib/compiler-rt/lib/cmpdi2.c
new file mode 100644
index 0000000..0b87352
--- /dev/null
+++ b/contrib/compiler-rt/lib/cmpdi2.c
@@ -0,0 +1,38 @@
+/* ===-- cmpdi2.c - Implement __cmpdi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __cmpdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: if (a < b) returns 0
+* if (a == b) returns 1
+* if (a > b) returns 2
+*/
+
+si_int
+__cmpdi2(di_int a, di_int b)
+{
+ dwords x;
+ x.all = a;
+ dwords y;
+ y.all = b;
+ if (x.s.high < y.s.high)
+ return 0;
+ if (x.s.high > y.s.high)
+ return 2;
+ if (x.s.low < y.s.low)
+ return 0;
+ if (x.s.low > y.s.low)
+ return 2;
+ return 1;
+}
diff --git a/contrib/compiler-rt/lib/cmpti2.c b/contrib/compiler-rt/lib/cmpti2.c
new file mode 100644
index 0000000..90b3b75
--- /dev/null
+++ b/contrib/compiler-rt/lib/cmpti2.c
@@ -0,0 +1,42 @@
+/* ===-- cmpti2.c - Implement __cmpti2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __cmpti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: if (a < b) returns 0
+ * if (a == b) returns 1
+ * if (a > b) returns 2
+ */
+
+si_int
+__cmpti2(ti_int a, ti_int b)
+{
+ twords x;
+ x.all = a;
+ twords y;
+ y.all = b;
+ if (x.s.high < y.s.high)
+ return 0;
+ if (x.s.high > y.s.high)
+ return 2;
+ if (x.s.low < y.s.low)
+ return 0;
+ if (x.s.low > y.s.low)
+ return 2;
+ return 1;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/comparedf2.c b/contrib/compiler-rt/lib/comparedf2.c
new file mode 100644
index 0000000..5c5ee9d
--- /dev/null
+++ b/contrib/compiler-rt/lib/comparedf2.c
@@ -0,0 +1,132 @@
+//===-- lib/comparedf2.c - Double-precision comparisons -----------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// // This file implements the following soft-float comparison routines:
+//
+// __eqdf2 __gedf2 __unorddf2
+// __ledf2 __gtdf2
+// __ltdf2
+// __nedf2
+//
+// The semantics of the routines grouped in each column are identical, so there
+// is a single implementation for each, and wrappers to provide the other names.
+//
+// The main routines behave as follows:
+//
+// __ledf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// 1 if either a or b is NaN
+//
+// __gedf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// -1 if either a or b is NaN
+//
+// __unorddf2(a,b) returns 0 if both a and b are numbers
+// 1 if either a or b is NaN
+//
+// Note that __ledf2( ) and __gedf2( ) are identical except in their handling of
+// NaN values.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+enum LE_RESULT {
+ LE_LESS = -1,
+ LE_EQUAL = 0,
+ LE_GREATER = 1,
+ LE_UNORDERED = 1
+};
+
+enum LE_RESULT __ledf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ // If either a or b is NaN, they are unordered.
+ if (aAbs > infRep || bAbs > infRep) return LE_UNORDERED;
+
+ // If a and b are both zeros, they are equal.
+ if ((aAbs | bAbs) == 0) return LE_EQUAL;
+
+ // If at least one of a and b is positive, we get the same result comparing
+ // a and b as signed integers as we would with a floating-point compare.
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+
+ // Otherwise, both are negative, so we need to flip the sense of the
+ // comparison to get the correct result. (This assumes a twos- or ones-
+ // complement integer representation; if integers are represented in a
+ // sign-magnitude representation, then this flip is incorrect).
+ else {
+ if (aInt > bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+}
+
+enum GE_RESULT {
+ GE_LESS = -1,
+ GE_EQUAL = 0,
+ GE_GREATER = 1,
+ GE_UNORDERED = -1 // Note: different from LE_UNORDERED
+};
+
+enum GE_RESULT __gedf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ if (aAbs > infRep || bAbs > infRep) return GE_UNORDERED;
+ if ((aAbs | bAbs) == 0) return GE_EQUAL;
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ } else {
+ if (aInt > bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ }
+}
+
+int __unorddf2(fp_t a, fp_t b) {
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+ return aAbs > infRep || bAbs > infRep;
+}
+
+// The following are alternative names for the preceeding routines.
+
+enum LE_RESULT __eqdf2(fp_t a, fp_t b) {
+ return __ledf2(a, b);
+}
+
+enum LE_RESULT __ltdf2(fp_t a, fp_t b) {
+ return __ledf2(a, b);
+}
+
+enum LE_RESULT __nedf2(fp_t a, fp_t b) {
+ return __ledf2(a, b);
+}
+
+enum GE_RESULT __gtdf2(fp_t a, fp_t b) {
+ return __gedf2(a, b);
+}
+
diff --git a/contrib/compiler-rt/lib/comparesf2.c b/contrib/compiler-rt/lib/comparesf2.c
new file mode 100644
index 0000000..fd05724
--- /dev/null
+++ b/contrib/compiler-rt/lib/comparesf2.c
@@ -0,0 +1,131 @@
+//===-- lib/comparesf2.c - Single-precision comparisons -----------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the following soft-fp_t comparison routines:
+//
+// __eqsf2 __gesf2 __unordsf2
+// __lesf2 __gtsf2
+// __ltsf2
+// __nesf2
+//
+// The semantics of the routines grouped in each column are identical, so there
+// is a single implementation for each, and wrappers to provide the other names.
+//
+// The main routines behave as follows:
+//
+// __lesf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// 1 if either a or b is NaN
+//
+// __gesf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// -1 if either a or b is NaN
+//
+// __unordsf2(a,b) returns 0 if both a and b are numbers
+// 1 if either a or b is NaN
+//
+// Note that __lesf2( ) and __gesf2( ) are identical except in their handling of
+// NaN values.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+enum LE_RESULT {
+ LE_LESS = -1,
+ LE_EQUAL = 0,
+ LE_GREATER = 1,
+ LE_UNORDERED = 1
+};
+
+enum LE_RESULT __lesf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ // If either a or b is NaN, they are unordered.
+ if (aAbs > infRep || bAbs > infRep) return LE_UNORDERED;
+
+ // If a and b are both zeros, they are equal.
+ if ((aAbs | bAbs) == 0) return LE_EQUAL;
+
+ // If at least one of a and b is positive, we get the same result comparing
+ // a and b as signed integers as we would with a fp_ting-point compare.
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+
+ // Otherwise, both are negative, so we need to flip the sense of the
+ // comparison to get the correct result. (This assumes a twos- or ones-
+ // complement integer representation; if integers are represented in a
+ // sign-magnitude representation, then this flip is incorrect).
+ else {
+ if (aInt > bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+}
+
+enum GE_RESULT {
+ GE_LESS = -1,
+ GE_EQUAL = 0,
+ GE_GREATER = 1,
+ GE_UNORDERED = -1 // Note: different from LE_UNORDERED
+};
+
+enum GE_RESULT __gesf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ if (aAbs > infRep || bAbs > infRep) return GE_UNORDERED;
+ if ((aAbs | bAbs) == 0) return GE_EQUAL;
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ } else {
+ if (aInt > bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ }
+}
+
+int __unordsf2(fp_t a, fp_t b) {
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+ return aAbs > infRep || bAbs > infRep;
+}
+
+// The following are alternative names for the preceeding routines.
+
+enum LE_RESULT __eqsf2(fp_t a, fp_t b) {
+ return __lesf2(a, b);
+}
+
+enum LE_RESULT __ltsf2(fp_t a, fp_t b) {
+ return __lesf2(a, b);
+}
+
+enum LE_RESULT __nesf2(fp_t a, fp_t b) {
+ return __lesf2(a, b);
+}
+
+enum GE_RESULT __gtsf2(fp_t a, fp_t b) {
+ return __gesf2(a, b);
+}
diff --git a/contrib/compiler-rt/lib/ctzdi2.c b/contrib/compiler-rt/lib/ctzdi2.c
new file mode 100644
index 0000000..b49f2c7
--- /dev/null
+++ b/contrib/compiler-rt/lib/ctzdi2.c
@@ -0,0 +1,29 @@
+/* ===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ctzdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: the number of trailing 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__ctzdi2(di_int a)
+{
+ dwords x;
+ x.all = a;
+ const si_int f = -(x.s.low == 0);
+ return __builtin_ctz((x.s.high & f) | (x.s.low & ~f)) +
+ (f & ((si_int)(sizeof(si_int) * CHAR_BIT)));
+}
diff --git a/contrib/compiler-rt/lib/ctzsi2.c b/contrib/compiler-rt/lib/ctzsi2.c
new file mode 100644
index 0000000..30d34c8
--- /dev/null
+++ b/contrib/compiler-rt/lib/ctzsi2.c
@@ -0,0 +1,57 @@
+/* ===-- ctzsi2.c - Implement __ctzsi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ctzsi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: the number of trailing 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__ctzsi2(si_int a)
+{
+ su_int x = (su_int)a;
+ si_int t = ((x & 0x0000FFFF) == 0) << 4; /* if (x has no small bits) t = 16 else 0 */
+ x >>= t; /* x = [0 - 0xFFFF] + higher garbage bits */
+ su_int r = t; /* r = [0, 16] */
+ /* return r + ctz(x) */
+ t = ((x & 0x00FF) == 0) << 3;
+ x >>= t; /* x = [0 - 0xFF] + higher garbage bits */
+ r += t; /* r = [0, 8, 16, 24] */
+ /* return r + ctz(x) */
+ t = ((x & 0x0F) == 0) << 2;
+ x >>= t; /* x = [0 - 0xF] + higher garbage bits */
+ r += t; /* r = [0, 4, 8, 12, 16, 20, 24, 28] */
+ /* return r + ctz(x) */
+ t = ((x & 0x3) == 0) << 1;
+ x >>= t;
+ x &= 3; /* x = [0 - 3] */
+ r += t; /* r = [0 - 30] and is even */
+ /* return r + ctz(x) */
+
+/* The branch-less return statement below is equivalent
+ * to the following switch statement:
+ * switch (x)
+ * {
+ * case 0:
+ * return r + 2;
+ * case 2:
+ * return r + 1;
+ * case 1:
+ * case 3:
+ * return r;
+ * }
+ */
+ return r + ((2 - (x >> 1)) & -((x & 1) == 0));
+}
diff --git a/contrib/compiler-rt/lib/ctzti2.c b/contrib/compiler-rt/lib/ctzti2.c
new file mode 100644
index 0000000..f2d41fe
--- /dev/null
+++ b/contrib/compiler-rt/lib/ctzti2.c
@@ -0,0 +1,33 @@
+/* ===-- ctzti2.c - Implement __ctzti2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ctzti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: the number of trailing 0-bits */
+
+/* Precondition: a != 0 */
+
+si_int
+__ctzti2(ti_int a)
+{
+ twords x;
+ x.all = a;
+ const di_int f = -(x.s.low == 0);
+ return __builtin_ctzll((x.s.high & f) | (x.s.low & ~f)) +
+ ((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/divdc3.c b/contrib/compiler-rt/lib/divdc3.c
new file mode 100644
index 0000000..c96aefd
--- /dev/null
+++ b/contrib/compiler-rt/lib/divdc3.c
@@ -0,0 +1,59 @@
+/* ===-- divdc3.c - Implement __divdc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divdc3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the quotient of (a + ib) / (c + id) */
+
+double _Complex
+__divdc3(double __a, double __b, double __c, double __d)
+{
+ int __ilogbw = 0;
+ double __logbw = logb(fmax(fabs(__c), fabs(__d)));
+ if (isfinite(__logbw))
+ {
+ __ilogbw = (int)__logbw;
+ __c = scalbn(__c, -__ilogbw);
+ __d = scalbn(__d, -__ilogbw);
+ }
+ double __denom = __c * __c + __d * __d;
+ double _Complex z;
+ __real__ z = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
+ __imag__ z = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ if ((__denom == 0.0) && (!isnan(__a) || !isnan(__b)))
+ {
+ __real__ z = copysign(INFINITY, __c) * __a;
+ __imag__ z = copysign(INFINITY, __c) * __b;
+ }
+ else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d))
+ {
+ __a = copysign(isinf(__a) ? 1.0 : 0.0, __a);
+ __b = copysign(isinf(__b) ? 1.0 : 0.0, __b);
+ __real__ z = INFINITY * (__a * __c + __b * __d);
+ __imag__ z = INFINITY * (__b * __c - __a * __d);
+ }
+ else if (isinf(__logbw) && __logbw > 0.0 && isfinite(__a) && isfinite(__b))
+ {
+ __c = copysign(isinf(__c) ? 1.0 : 0.0, __c);
+ __d = copysign(isinf(__d) ? 1.0 : 0.0, __d);
+ __real__ z = 0.0 * (__a * __c + __b * __d);
+ __imag__ z = 0.0 * (__b * __c - __a * __d);
+ }
+ }
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/divdf3.c b/contrib/compiler-rt/lib/divdf3.c
new file mode 100644
index 0000000..21b8f09
--- /dev/null
+++ b/contrib/compiler-rt/lib/divdf3.c
@@ -0,0 +1,182 @@
+//===-- lib/divdf3.c - Double-precision division ------------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements double-precision soft-float division
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+// For simplicity, this implementation currently flushes denormals to zero.
+// It should be a fairly straightforward exercise to implement gradual
+// underflow with correct rounding.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __divdf3(fp_t a, fp_t b) {
+
+ const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
+ const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
+ const rep_t quotientSign = (toRep(a) ^ toRep(b)) & signBit;
+
+ rep_t aSignificand = toRep(a) & significandMask;
+ rep_t bSignificand = toRep(b) & significandMask;
+ int scale = 0;
+
+ // Detect if a or b is zero, denormal, infinity, or NaN.
+ if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
+
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+
+ // NaN / anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything / NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // infinity / infinity = NaN
+ if (bAbs == infRep) return fromRep(qnanRep);
+ // infinity / anything else = +/- infinity
+ else return fromRep(aAbs | quotientSign);
+ }
+
+ // anything else / infinity = +/- 0
+ if (bAbs == infRep) return fromRep(quotientSign);
+
+ if (!aAbs) {
+ // zero / zero = NaN
+ if (!bAbs) return fromRep(qnanRep);
+ // zero / anything else = +/- zero
+ else return fromRep(quotientSign);
+ }
+ // anything else / zero = +/- infinity
+ if (!bAbs) return fromRep(infRep | quotientSign);
+
+ // one or both of a or b is denormal, the other (if applicable) is a
+ // normal number. Renormalize one or both of a and b, and set scale to
+ // include the necessary exponent adjustment.
+ if (aAbs < implicitBit) scale += normalize(&aSignificand);
+ if (bAbs < implicitBit) scale -= normalize(&bSignificand);
+ }
+
+ // Or in the implicit significand bit. (If we fell through from the
+ // denormal path it was already set by normalize( ), but setting it twice
+ // won't hurt anything.)
+ aSignificand |= implicitBit;
+ bSignificand |= implicitBit;
+ int quotientExponent = aExponent - bExponent + scale;
+
+ // Align the significand of b as a Q31 fixed-point number in the range
+ // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
+ // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
+ // is accurate to about 3.5 binary digits.
+ const uint32_t q31b = bSignificand >> 21;
+ uint32_t recip32 = UINT32_C(0x7504f333) - q31b;
+
+ // Now refine the reciprocal estimate using a Newton-Raphson iteration:
+ //
+ // x1 = x0 * (2 - x0 * b)
+ //
+ // This doubles the number of correct binary digits in the approximation
+ // with each iteration, so after three iterations, we have about 28 binary
+ // digits of accuracy.
+ uint32_t correction32;
+ correction32 = -((uint64_t)recip32 * q31b >> 32);
+ recip32 = (uint64_t)recip32 * correction32 >> 31;
+ correction32 = -((uint64_t)recip32 * q31b >> 32);
+ recip32 = (uint64_t)recip32 * correction32 >> 31;
+ correction32 = -((uint64_t)recip32 * q31b >> 32);
+ recip32 = (uint64_t)recip32 * correction32 >> 31;
+
+ // recip32 might have overflowed to exactly zero in the preceeding
+ // computation if the high word of b is exactly 1.0. This would sabotage
+ // the full-width final stage of the computation that follows, so we adjust
+ // recip32 downward by one bit.
+ recip32--;
+
+ // We need to perform one more iteration to get us to 56 binary digits;
+ // The last iteration needs to happen with extra precision.
+ const uint32_t q63blo = bSignificand << 11;
+ uint64_t correction, reciprocal;
+ correction = -((uint64_t)recip32*q31b + ((uint64_t)recip32*q63blo >> 32));
+ uint32_t cHi = correction >> 32;
+ uint32_t cLo = correction;
+ reciprocal = (uint64_t)recip32*cHi + ((uint64_t)recip32*cLo >> 32);
+
+ // We already adjusted the 32-bit estimate, now we need to adjust the final
+ // 64-bit reciprocal estimate downward to ensure that it is strictly smaller
+ // than the infinitely precise exact reciprocal. Because the computation
+ // of the Newton-Raphson step is truncating at every step, this adjustment
+ // is small; most of the work is already done.
+ reciprocal -= 2;
+
+ // The numerical reciprocal is accurate to within 2^-56, lies in the
+ // interval [0.5, 1.0), and is strictly smaller than the true reciprocal
+ // of b. Multiplying a by this reciprocal thus gives a numerical q = a/b
+ // in Q53 with the following properties:
+ //
+ // 1. q < a/b
+ // 2. q is in the interval [0.5, 2.0)
+ // 3. the error in q is bounded away from 2^-53 (actually, we have a
+ // couple of bits to spare, but this is all we need).
+
+ // We need a 64 x 64 multiply high to compute q, which isn't a basic
+ // operation in C, so we need to be a little bit fussy.
+ rep_t quotient, quotientLo;
+ wideMultiply(aSignificand << 2, reciprocal, &quotient, &quotientLo);
+
+ // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
+ // In either case, we are going to compute a residual of the form
+ //
+ // r = a - q*b
+ //
+ // We know from the construction of q that r satisfies:
+ //
+ // 0 <= r < ulp(q)*b
+ //
+ // if r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
+ // already have the correct result. The exact halfway case cannot occur.
+ // We also take this time to right shift quotient if it falls in the [1,2)
+ // range and adjust the exponent accordingly.
+ rep_t residual;
+ if (quotient < (implicitBit << 1)) {
+ residual = (aSignificand << 53) - quotient * bSignificand;
+ quotientExponent--;
+ } else {
+ quotient >>= 1;
+ residual = (aSignificand << 52) - quotient * bSignificand;
+ }
+
+ const int writtenExponent = quotientExponent + exponentBias;
+
+ if (writtenExponent >= maxExponent) {
+ // If we have overflowed the exponent, return infinity.
+ return fromRep(infRep | quotientSign);
+ }
+
+ else if (writtenExponent < 1) {
+ // Flush denormals to zero. In the future, it would be nice to add
+ // code to round them correctly.
+ return fromRep(quotientSign);
+ }
+
+ else {
+ const bool round = (residual << 1) > bSignificand;
+ // Clear the implicit bit
+ rep_t absResult = quotient & significandMask;
+ // Insert the exponent
+ absResult |= (rep_t)writtenExponent << significandBits;
+ // Round
+ absResult += round;
+ // Insert the sign and return
+ const double result = fromRep(absResult | quotientSign);
+ return result;
+ }
+}
diff --git a/contrib/compiler-rt/lib/divdi3.c b/contrib/compiler-rt/lib/divdi3.c
new file mode 100644
index 0000000..fccfb8b
--- /dev/null
+++ b/contrib/compiler-rt/lib/divdi3.c
@@ -0,0 +1,31 @@
+/* ===-- divdi3.c - Implement __divdi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
+
+/* Returns: a / b */
+
+di_int
+__divdi3(di_int a, di_int b)
+{
+ const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
+ di_int s_a = a >> bits_in_dword_m1; /* s_a = a < 0 ? -1 : 0 */
+ di_int s_b = b >> bits_in_dword_m1; /* s_b = b < 0 ? -1 : 0 */
+ a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
+ b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
+ s_a ^= s_b; /*sign of quotient */
+ return (__udivmoddi4(a, b, (du_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */
+}
diff --git a/contrib/compiler-rt/lib/divsc3.c b/contrib/compiler-rt/lib/divsc3.c
new file mode 100644
index 0000000..c38c863
--- /dev/null
+++ b/contrib/compiler-rt/lib/divsc3.c
@@ -0,0 +1,59 @@
+/*===-- divsc3.c - Implement __divsc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divsc3 for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the quotient of (a + ib) / (c + id) */
+
+float _Complex
+__divsc3(float __a, float __b, float __c, float __d)
+{
+ int __ilogbw = 0;
+ float __logbw = logbf(fmaxf(fabsf(__c), fabsf(__d)));
+ if (isfinite(__logbw))
+ {
+ __ilogbw = (int)__logbw;
+ __c = scalbnf(__c, -__ilogbw);
+ __d = scalbnf(__d, -__ilogbw);
+ }
+ float __denom = __c * __c + __d * __d;
+ float _Complex z;
+ __real__ z = scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw);
+ __imag__ z = scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw);
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ if ((__denom == 0) && (!isnan(__a) || !isnan(__b)))
+ {
+ __real__ z = copysignf(INFINITY, __c) * __a;
+ __imag__ z = copysignf(INFINITY, __c) * __b;
+ }
+ else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d))
+ {
+ __a = copysignf(isinf(__a) ? 1 : 0, __a);
+ __b = copysignf(isinf(__b) ? 1 : 0, __b);
+ __real__ z = INFINITY * (__a * __c + __b * __d);
+ __imag__ z = INFINITY * (__b * __c - __a * __d);
+ }
+ else if (isinf(__logbw) && __logbw > 0 && isfinite(__a) && isfinite(__b))
+ {
+ __c = copysignf(isinf(__c) ? 1 : 0, __c);
+ __d = copysignf(isinf(__d) ? 1 : 0, __d);
+ __real__ z = 0 * (__a * __c + __b * __d);
+ __imag__ z = 0 * (__b * __c - __a * __d);
+ }
+ }
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/divsf3.c b/contrib/compiler-rt/lib/divsf3.c
new file mode 100644
index 0000000..03b7311
--- /dev/null
+++ b/contrib/compiler-rt/lib/divsf3.c
@@ -0,0 +1,166 @@
+//===-- lib/divsf3.c - Single-precision division ------------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements single-precision soft-float division
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+// For simplicity, this implementation currently flushes denormals to zero.
+// It should be a fairly straightforward exercise to implement gradual
+// underflow with correct rounding.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __divsf3(fp_t a, fp_t b) {
+
+ const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
+ const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
+ const rep_t quotientSign = (toRep(a) ^ toRep(b)) & signBit;
+
+ rep_t aSignificand = toRep(a) & significandMask;
+ rep_t bSignificand = toRep(b) & significandMask;
+ int scale = 0;
+
+ // Detect if a or b is zero, denormal, infinity, or NaN.
+ if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
+
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+
+ // NaN / anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything / NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // infinity / infinity = NaN
+ if (bAbs == infRep) return fromRep(qnanRep);
+ // infinity / anything else = +/- infinity
+ else return fromRep(aAbs | quotientSign);
+ }
+
+ // anything else / infinity = +/- 0
+ if (bAbs == infRep) return fromRep(quotientSign);
+
+ if (!aAbs) {
+ // zero / zero = NaN
+ if (!bAbs) return fromRep(qnanRep);
+ // zero / anything else = +/- zero
+ else return fromRep(quotientSign);
+ }
+ // anything else / zero = +/- infinity
+ if (!bAbs) return fromRep(infRep | quotientSign);
+
+ // one or both of a or b is denormal, the other (if applicable) is a
+ // normal number. Renormalize one or both of a and b, and set scale to
+ // include the necessary exponent adjustment.
+ if (aAbs < implicitBit) scale += normalize(&aSignificand);
+ if (bAbs < implicitBit) scale -= normalize(&bSignificand);
+ }
+
+ // Or in the implicit significand bit. (If we fell through from the
+ // denormal path it was already set by normalize( ), but setting it twice
+ // won't hurt anything.)
+ aSignificand |= implicitBit;
+ bSignificand |= implicitBit;
+ int quotientExponent = aExponent - bExponent + scale;
+
+ // Align the significand of b as a Q31 fixed-point number in the range
+ // [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
+ // polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
+ // is accurate to about 3.5 binary digits.
+ uint32_t q31b = bSignificand << 8;
+ uint32_t reciprocal = UINT32_C(0x7504f333) - q31b;
+
+ // Now refine the reciprocal estimate using a Newton-Raphson iteration:
+ //
+ // x1 = x0 * (2 - x0 * b)
+ //
+ // This doubles the number of correct binary digits in the approximation
+ // with each iteration, so after three iterations, we have about 28 binary
+ // digits of accuracy.
+ uint32_t correction;
+ correction = -((uint64_t)reciprocal * q31b >> 32);
+ reciprocal = (uint64_t)reciprocal * correction >> 31;
+ correction = -((uint64_t)reciprocal * q31b >> 32);
+ reciprocal = (uint64_t)reciprocal * correction >> 31;
+ correction = -((uint64_t)reciprocal * q31b >> 32);
+ reciprocal = (uint64_t)reciprocal * correction >> 31;
+
+ // Exhaustive testing shows that the error in reciprocal after three steps
+ // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
+ // expectations. We bump the reciprocal by a tiny value to force the error
+ // to be strictly positive (in the range [0x1.4fdfp-37,0x1.287246p-29], to
+ // be specific). This also causes 1/1 to give a sensible approximation
+ // instead of zero (due to overflow).
+ reciprocal -= 2;
+
+ // The numerical reciprocal is accurate to within 2^-28, lies in the
+ // interval [0x1.000000eep-1, 0x1.fffffffcp-1], and is strictly smaller
+ // than the true reciprocal of b. Multiplying a by this reciprocal thus
+ // gives a numerical q = a/b in Q24 with the following properties:
+ //
+ // 1. q < a/b
+ // 2. q is in the interval [0x1.000000eep-1, 0x1.fffffffcp0)
+ // 3. the error in q is at most 2^-24 + 2^-27 -- the 2^24 term comes
+ // from the fact that we truncate the product, and the 2^27 term
+ // is the error in the reciprocal of b scaled by the maximum
+ // possible value of a. As a consequence of this error bound,
+ // either q or nextafter(q) is the correctly rounded
+ rep_t quotient = (uint64_t)reciprocal*(aSignificand << 1) >> 32;
+
+ // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
+ // In either case, we are going to compute a residual of the form
+ //
+ // r = a - q*b
+ //
+ // We know from the construction of q that r satisfies:
+ //
+ // 0 <= r < ulp(q)*b
+ //
+ // if r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
+ // already have the correct result. The exact halfway case cannot occur.
+ // We also take this time to right shift quotient if it falls in the [1,2)
+ // range and adjust the exponent accordingly.
+ rep_t residual;
+ if (quotient < (implicitBit << 1)) {
+ residual = (aSignificand << 24) - quotient * bSignificand;
+ quotientExponent--;
+ } else {
+ quotient >>= 1;
+ residual = (aSignificand << 23) - quotient * bSignificand;
+ }
+
+ const int writtenExponent = quotientExponent + exponentBias;
+
+ if (writtenExponent >= maxExponent) {
+ // If we have overflowed the exponent, return infinity.
+ return fromRep(infRep | quotientSign);
+ }
+
+ else if (writtenExponent < 1) {
+ // Flush denormals to zero. In the future, it would be nice to add
+ // code to round them correctly.
+ return fromRep(quotientSign);
+ }
+
+ else {
+ const bool round = (residual << 1) > bSignificand;
+ // Clear the implicit bit
+ rep_t absResult = quotient & significandMask;
+ // Insert the exponent
+ absResult |= (rep_t)writtenExponent << significandBits;
+ // Round
+ absResult += round;
+ // Insert the sign and return
+ return fromRep(absResult | quotientSign);
+ }
+}
diff --git a/contrib/compiler-rt/lib/divsi3.c b/contrib/compiler-rt/lib/divsi3.c
new file mode 100644
index 0000000..0eff6ef
--- /dev/null
+++ b/contrib/compiler-rt/lib/divsi3.c
@@ -0,0 +1,31 @@
+/* ===-- divsi3.c - Implement __divsi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+su_int __udivsi3(su_int n, su_int d);
+
+/* Returns: a / b */
+
+si_int
+__divsi3(si_int a, si_int b)
+{
+ const int bits_in_word_m1 = (int)(sizeof(si_int) * CHAR_BIT) - 1;
+ si_int s_a = a >> bits_in_word_m1; /* s_a = a < 0 ? -1 : 0 */
+ si_int s_b = b >> bits_in_word_m1; /* s_b = b < 0 ? -1 : 0 */
+ a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
+ b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
+ s_a ^= s_b; /* sign of quotient */
+ return (__udivsi3(a, b) ^ s_a) - s_a; /* negate if s_a == -1 */
+}
diff --git a/contrib/compiler-rt/lib/divti3.c b/contrib/compiler-rt/lib/divti3.c
new file mode 100644
index 0000000..c752f6c
--- /dev/null
+++ b/contrib/compiler-rt/lib/divti3.c
@@ -0,0 +1,35 @@
+/* ===-- divti3.c - Implement __divti3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
+
+/* Returns: a / b */
+
+ti_int
+__divti3(ti_int a, ti_int b)
+{
+ const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
+ ti_int s_a = a >> bits_in_tword_m1; /* s_a = a < 0 ? -1 : 0 */
+ ti_int s_b = b >> bits_in_tword_m1; /* s_b = b < 0 ? -1 : 0 */
+ a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
+ b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
+ s_a ^= s_b; /* sign of quotient */
+ return (__udivmodti4(a, b, (tu_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/divxc3.c b/contrib/compiler-rt/lib/divxc3.c
new file mode 100644
index 0000000..03357ae
--- /dev/null
+++ b/contrib/compiler-rt/lib/divxc3.c
@@ -0,0 +1,62 @@
+/* ===-- divxc3.c - Implement __divxc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __divxc3 for the compiler_rt library.
+ *
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the quotient of (a + ib) / (c + id) */
+
+long double _Complex
+__divxc3(long double __a, long double __b, long double __c, long double __d)
+{
+ int __ilogbw = 0;
+ long double __logbw = logbl(fmaxl(fabsl(__c), fabsl(__d)));
+ if (isfinite(__logbw))
+ {
+ __ilogbw = (int)__logbw;
+ __c = scalbnl(__c, -__ilogbw);
+ __d = scalbnl(__d, -__ilogbw);
+ }
+ long double __denom = __c * __c + __d * __d;
+ long double _Complex z;
+ __real__ z = scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw);
+ __imag__ z = scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw);
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ if ((__denom == 0) && (!isnan(__a) || !isnan(__b)))
+ {
+ __real__ z = copysignl(INFINITY, __c) * __a;
+ __imag__ z = copysignl(INFINITY, __c) * __b;
+ }
+ else if ((isinf(__a) || isinf(__b)) && isfinite(__c) && isfinite(__d))
+ {
+ __a = copysignl(isinf(__a) ? 1 : 0, __a);
+ __b = copysignl(isinf(__b) ? 1 : 0, __b);
+ __real__ z = INFINITY * (__a * __c + __b * __d);
+ __imag__ z = INFINITY * (__b * __c - __a * __d);
+ }
+ else if (isinf(__logbw) && __logbw > 0 && isfinite(__a) && isfinite(__b))
+ {
+ __c = copysignl(isinf(__c) ? 1 : 0, __c);
+ __d = copysignl(isinf(__d) ? 1 : 0, __d);
+ __real__ z = 0 * (__a * __c + __b * __d);
+ __imag__ z = 0 * (__b * __c - __a * __d);
+ }
+ }
+ return z;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/enable_execute_stack.c b/contrib/compiler-rt/lib/enable_execute_stack.c
new file mode 100644
index 0000000..193e7db
--- /dev/null
+++ b/contrib/compiler-rt/lib/enable_execute_stack.c
@@ -0,0 +1,58 @@
+/* ===-- enable_execute_stack.c - Implement __enable_execute_stack ---------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include <stdint.h>
+#include <sys/mman.h>
+
+/* #include "config.h"
+ * FIXME: CMake - include when cmake system is ready.
+ * Remove #define HAVE_SYSCONF 1 line.
+ */
+#define HAVE_SYSCONF 1
+
+#ifndef __APPLE__
+#include <unistd.h>
+#endif /* __APPLE__ */
+
+#if __LP64__
+ #define TRAMPOLINE_SIZE 48
+#else
+ #define TRAMPOLINE_SIZE 40
+#endif
+
+/*
+ * The compiler generates calls to __enable_execute_stack() when creating
+ * trampoline functions on the stack for use with nested functions.
+ * It is expected to mark the page(s) containing the address
+ * and the next 48 bytes as executable. Since the stack is normally rw-
+ * that means changing the protection on those page(s) to rwx.
+ */
+
+void __enable_execute_stack(void* addr)
+{
+
+#if __APPLE__
+ /* On Darwin, pagesize is always 4096 bytes */
+ const uintptr_t pageSize = 4096;
+#elif !defined(HAVE_SYSCONF)
+#error "HAVE_SYSCONF not defined! See enable_execute_stack.c"
+#else
+ const uintptr_t pageSize = sysconf(_SC_PAGESIZE);
+#endif /* __APPLE__ */
+
+ const uintptr_t pageAlignMask = ~(pageSize-1);
+ uintptr_t p = (uintptr_t)addr;
+ unsigned char* startPage = (unsigned char*)(p & pageAlignMask);
+ unsigned char* endPage = (unsigned char*)((p+TRAMPOLINE_SIZE+pageSize) & pageAlignMask);
+ size_t length = endPage - startPage;
+ (void) mprotect((void *)startPage, length, PROT_READ | PROT_WRITE | PROT_EXEC);
+}
+
+
diff --git a/contrib/compiler-rt/lib/endianness.h b/contrib/compiler-rt/lib/endianness.h
new file mode 100644
index 0000000..6d2587d
--- /dev/null
+++ b/contrib/compiler-rt/lib/endianness.h
@@ -0,0 +1,94 @@
+/* ===-- endianness.h - configuration header for compiler-rt ---------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file is a configuration header for compiler-rt.
+ * This file is not part of the interface of this library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#ifndef ENDIANNESS_H
+#define ENDIANNESS_H
+
+/*
+ * Known limitations:
+ * Middle endian systems are not handled currently.
+ */
+
+#if defined(__SVR4) && defined(__sun)
+#include <sys/byteorder.h>
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 0
+#define _YUGA_BIG_ENDIAN 1
+#elif _BYTE_ORDER == _LITTLE_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 1
+#define _YUGA_BIG_ENDIAN 0
+#endif /* _BYTE_ORDER */
+
+#endif /* Solaris and AuroraUX. */
+
+/* .. */
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#include <sys/endian.h>
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 0
+#define _YUGA_BIG_ENDIAN 1
+#elif _BYTE_ORDER == _LITTLE_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 1
+#define _YUGA_BIG_ENDIAN 0
+#endif /* _BYTE_ORDER */
+
+#endif /* *BSD */
+
+/* .. */
+
+/* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */
+#if defined(__APPLE__) && defined(__MACH__) || defined(__ellcc__ )
+
+#ifdef __BIG_ENDIAN__
+#if __BIG_ENDIAN__
+#define _YUGA_LITTLE_ENDIAN 0
+#define _YUGA_BIG_ENDIAN 1
+#endif
+#endif /* __BIG_ENDIAN__ */
+
+#ifdef __LITTLE_ENDIAN__
+#if __LITTLE_ENDIAN__
+#define _YUGA_LITTLE_ENDIAN 1
+#define _YUGA_BIG_ENDIAN 0
+#endif
+#endif /* __LITTLE_ENDIAN__ */
+
+#endif /* Mac OSX */
+
+/* .. */
+
+#if defined(__linux__)
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 0
+#define _YUGA_BIG_ENDIAN 1
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+#define _YUGA_LITTLE_ENDIAN 1
+#define _YUGA_BIG_ENDIAN 0
+#endif /* __BYTE_ORDER */
+
+#endif /* GNU/Linux */
+
+/* . */
+
+#if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
+#error Unable to determine endian
+#endif /* Check we found an endianness correctly. */
+
+#endif /* ENDIANNESS_H */
diff --git a/contrib/compiler-rt/lib/eprintf.c b/contrib/compiler-rt/lib/eprintf.c
new file mode 100644
index 0000000..786fe6a
--- /dev/null
+++ b/contrib/compiler-rt/lib/eprintf.c
@@ -0,0 +1,33 @@
+/* ===---------- eprintf.c - Implements __eprintf --------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+
+
+#include "int_lib.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/*
+ * __eprintf() was used in an old version of <assert.h>.
+ * It can eventually go away, but it is needed when linking
+ * .o files built with the old <assert.h>.
+ *
+ * It should never be exported from a dylib, so it is marked
+ * visibility hidden.
+ */
+__attribute__((visibility("hidden")))
+void __eprintf(const char* format, const char* assertion_expression,
+ const char* line, const char* file)
+{
+ fprintf(stderr, format, assertion_expression, line, file);
+ fflush(stderr);
+ compilerrt_abort();
+}
diff --git a/contrib/compiler-rt/lib/extendsfdf2.c b/contrib/compiler-rt/lib/extendsfdf2.c
new file mode 100644
index 0000000..025eb95
--- /dev/null
+++ b/contrib/compiler-rt/lib/extendsfdf2.c
@@ -0,0 +1,136 @@
+//===-- lib/extendsfdf2.c - single -> double conversion -----------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a fairly generic conversion from a narrower to a wider
+// IEEE-754 floating-point type. The constants and types defined following the
+// includes below parameterize the conversion.
+//
+// This routine can be trivially adapted to support conversions from
+// half-precision or to quad-precision. It does not support types that don't
+// use the usual IEEE-754 interchange formats; specifically, some work would be
+// needed to adapt it to (for example) the Intel 80-bit format or PowerPC
+// double-double format.
+//
+// Note please, however, that this implementation is only intended to support
+// *widening* operations; if you need to convert to a *narrower* floating-point
+// type (e.g. double -> float), then this routine will not do what you want it
+// to.
+//
+// It also requires that integer types at least as large as both formats
+// are available on the target platform; this may pose a problem when trying
+// to add support for quad on some 32-bit systems, for example. You also may
+// run into trouble finding an appropriate CLZ function for wide source types;
+// you will likely need to roll your own on some platforms.
+//
+// Finally, the following assumptions are made:
+//
+// 1. floating-point types and integer types have the same endianness on the
+// target platform
+//
+// 2. quiet NaNs, if supported, are indicated by the leading bit of the
+// significand field being set
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <limits.h>
+
+typedef float src_t;
+typedef uint32_t src_rep_t;
+#define SRC_REP_C UINT32_C
+static const int srcSigBits = 23;
+#define src_rep_t_clz __builtin_clz
+
+typedef double dst_t;
+typedef uint64_t dst_rep_t;
+#define DST_REP_C UINT64_C
+static const int dstSigBits = 52;
+
+// End of specialization parameters. Two helper routines for conversion to and
+// from the representation of floating-point data as integer values follow.
+
+static inline src_rep_t srcToRep(src_t x) {
+ const union { src_t f; src_rep_t i; } rep = {.f = x};
+ return rep.i;
+}
+
+static inline dst_t dstFromRep(dst_rep_t x) {
+ const union { dst_t f; dst_rep_t i; } rep = {.i = x};
+ return rep.f;
+}
+
+// End helper routines. Conversion implementation follows.
+
+dst_t __extendsfdf2(src_t a) {
+
+ // Various constants whose values follow from the type parameters.
+ // Any reasonable optimizer will fold and propagate all of these.
+ const int srcBits = sizeof(src_t)*CHAR_BIT;
+ const int srcExpBits = srcBits - srcSigBits - 1;
+ const int srcInfExp = (1 << srcExpBits) - 1;
+ const int srcExpBias = srcInfExp >> 1;
+
+ const src_rep_t srcMinNormal = SRC_REP_C(1) << srcSigBits;
+ const src_rep_t srcInfinity = (src_rep_t)srcInfExp << srcSigBits;
+ const src_rep_t srcSignMask = SRC_REP_C(1) << (srcSigBits + srcExpBits);
+ const src_rep_t srcAbsMask = srcSignMask - 1;
+ const src_rep_t srcQNaN = SRC_REP_C(1) << (srcSigBits - 1);
+ const src_rep_t srcNaNCode = srcQNaN - 1;
+
+ const int dstBits = sizeof(dst_t)*CHAR_BIT;
+ const int dstExpBits = dstBits - dstSigBits - 1;
+ const int dstInfExp = (1 << dstExpBits) - 1;
+ const int dstExpBias = dstInfExp >> 1;
+
+ const dst_rep_t dstMinNormal = DST_REP_C(1) << dstSigBits;
+
+ // Break a into a sign and representation of the absolute value
+ const src_rep_t aRep = srcToRep(a);
+ const src_rep_t aAbs = aRep & srcAbsMask;
+ const src_rep_t sign = aRep & srcSignMask;
+ dst_rep_t absResult;
+
+ if (aAbs - srcMinNormal < srcInfinity - srcMinNormal) {
+ // a is a normal number.
+ // Extend to the destination type by shifting the significand and
+ // exponent into the proper position and rebiasing the exponent.
+ absResult = (dst_rep_t)aAbs << (dstSigBits - srcSigBits);
+ absResult += (dst_rep_t)(dstExpBias - srcExpBias) << dstSigBits;
+ }
+
+ else if (aAbs >= srcInfinity) {
+ // a is NaN or infinity.
+ // Conjure the result by beginning with infinity, then setting the qNaN
+ // bit (if needed) and right-aligning the rest of the trailing NaN
+ // payload field.
+ absResult = (dst_rep_t)dstInfExp << dstSigBits;
+ absResult |= (dst_rep_t)(aAbs & srcQNaN) << (dstSigBits - srcSigBits);
+ absResult |= aAbs & srcNaNCode;
+ }
+
+ else if (aAbs) {
+ // a is denormal.
+ // renormalize the significand and clear the leading bit, then insert
+ // the correct adjusted exponent in the destination type.
+ const int scale = src_rep_t_clz(aAbs) - src_rep_t_clz(srcMinNormal);
+ absResult = (dst_rep_t)aAbs << (dstSigBits - srcSigBits + scale);
+ absResult ^= dstMinNormal;
+ const int resultExponent = dstExpBias - srcExpBias - scale + 1;
+ absResult |= (dst_rep_t)resultExponent << dstSigBits;
+ }
+
+ else {
+ // a is zero.
+ absResult = 0;
+ }
+
+ // Apply the signbit to (dst_t)abs(a).
+ const dst_rep_t result = absResult | (dst_rep_t)sign << (dstBits - srcBits);
+ return dstFromRep(result);
+}
diff --git a/contrib/compiler-rt/lib/ffsdi2.c b/contrib/compiler-rt/lib/ffsdi2.c
new file mode 100644
index 0000000..8c03d19
--- /dev/null
+++ b/contrib/compiler-rt/lib/ffsdi2.c
@@ -0,0 +1,33 @@
+/* ===-- ffsdi2.c - Implement __ffsdi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ffsdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: the index of the least significant 1-bit in a, or
+ * the value zero if a is zero. The least significant bit is index one.
+ */
+
+si_int
+__ffsdi2(di_int a)
+{
+ dwords x;
+ x.all = a;
+ if (x.s.low == 0)
+ {
+ if (x.s.high == 0)
+ return 0;
+ return __builtin_ctz(x.s.high) + (1 + sizeof(si_int) * CHAR_BIT);
+ }
+ return __builtin_ctz(x.s.low) + 1;
+}
diff --git a/contrib/compiler-rt/lib/ffsti2.c b/contrib/compiler-rt/lib/ffsti2.c
new file mode 100644
index 0000000..0139eb1
--- /dev/null
+++ b/contrib/compiler-rt/lib/ffsti2.c
@@ -0,0 +1,37 @@
+/* ===-- ffsti2.c - Implement __ffsti2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ffsti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: the index of the least significant 1-bit in a, or
+ * the value zero if a is zero. The least significant bit is index one.
+ */
+
+si_int
+__ffsti2(ti_int a)
+{
+ twords x;
+ x.all = a;
+ if (x.s.low == 0)
+ {
+ if (x.s.high == 0)
+ return 0;
+ return __builtin_ctzll(x.s.high) + (1 + sizeof(di_int) * CHAR_BIT);
+ }
+ return __builtin_ctzll(x.s.low) + 1;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/fixdfdi.c b/contrib/compiler-rt/lib/fixdfdi.c
new file mode 100644
index 0000000..3d3116c
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixdfdi.c
@@ -0,0 +1,43 @@
+/* ===-- fixdfdi.c - Implement __fixdfdi -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixdfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in double is representable in di_int (no range checking performed)
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+di_int
+__fixdfdi(double a)
+{
+ double_bits fb;
+ fb.f = a;
+ int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
+ if (e < 0)
+ return 0;
+ di_int s = (si_int)(fb.u.s.high & 0x80000000) >> 31;
+ dwords r;
+ r.s.high = (fb.u.s.high & 0x000FFFFF) | 0x00100000;
+ r.s.low = fb.u.s.low;
+ if (e > 52)
+ r.all <<= (e - 52);
+ else
+ r.all >>= (52 - e);
+ return (r.all ^ s) - s;
+}
diff --git a/contrib/compiler-rt/lib/fixdfsi.c b/contrib/compiler-rt/lib/fixdfsi.c
new file mode 100644
index 0000000..7d17aed
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixdfsi.c
@@ -0,0 +1,45 @@
+//===-- lib/fixdfsi.c - Double-precision -> integer conversion ----*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements double-precision to integer conversion for the
+// compiler-rt library. No range checking is performed; the behavior of this
+// conversion is undefined for out of range values in the C standard.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+int __fixdfsi(fp_t a) {
+
+ // Break a into sign, exponent, significand
+ const rep_t aRep = toRep(a);
+ const rep_t aAbs = aRep & absMask;
+ const int sign = aRep & signBit ? -1 : 1;
+ const int exponent = (aAbs >> significandBits) - exponentBias;
+ const rep_t significand = (aAbs & significandMask) | implicitBit;
+
+ // If 0 < exponent < significandBits, right shift to get the result.
+ if ((unsigned int)exponent < significandBits) {
+ return sign * (significand >> (significandBits - exponent));
+ }
+
+ // If exponent is negative, the result is zero.
+ else if (exponent < 0) {
+ return 0;
+ }
+
+ // If significandBits < exponent, left shift to get the result. This shift
+ // may end up being larger than the type width, which incurs undefined
+ // behavior, but the conversion itself is undefined in that case, so
+ // whatever the compiler decides to do is fine.
+ else {
+ return sign * (significand << (exponent - significandBits));
+ }
+}
diff --git a/contrib/compiler-rt/lib/fixdfti.c b/contrib/compiler-rt/lib/fixdfti.c
new file mode 100644
index 0000000..359b84e
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixdfti.c
@@ -0,0 +1,45 @@
+/* ===-- fixdfti.c - Implement __fixdfti -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixdfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in double is representable in ti_int (no range checking performed)
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+ti_int
+__fixdfti(double a)
+{
+ double_bits fb;
+ fb.f = a;
+ int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
+ if (e < 0)
+ return 0;
+ ti_int s = (si_int)(fb.u.s.high & 0x80000000) >> 31;
+ ti_int r = 0x0010000000000000uLL | (0x000FFFFFFFFFFFFFuLL & fb.u.all);
+ if (e > 52)
+ r <<= (e - 52);
+ else
+ r >>= (52 - e);
+ return (r ^ s) - s;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixsfdi.c b/contrib/compiler-rt/lib/fixsfdi.c
new file mode 100644
index 0000000..08f1524
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixsfdi.c
@@ -0,0 +1,41 @@
+/* ===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixsfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in float is representable in di_int (no range checking performed)
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+di_int
+__fixsfdi(float a)
+{
+ float_bits fb;
+ fb.f = a;
+ int e = ((fb.u & 0x7F800000) >> 23) - 127;
+ if (e < 0)
+ return 0;
+ di_int s = (si_int)(fb.u & 0x80000000) >> 31;
+ di_int r = (fb.u & 0x007FFFFF) | 0x00800000;
+ if (e > 23)
+ r <<= (e - 23);
+ else
+ r >>= (23 - e);
+ return (r ^ s) - s;
+}
diff --git a/contrib/compiler-rt/lib/fixsfsi.c b/contrib/compiler-rt/lib/fixsfsi.c
new file mode 100644
index 0000000..ff79377
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixsfsi.c
@@ -0,0 +1,45 @@
+//===-- lib/fixsfsi.c - Single-precision -> integer conversion ----*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements single-precision to integer conversion for the
+// compiler-rt library. No range checking is performed; the behavior of this
+// conversion is undefined for out of range values in the C standard.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+int __fixsfsi(fp_t a) {
+
+ // Break a into sign, exponent, significand
+ const rep_t aRep = toRep(a);
+ const rep_t aAbs = aRep & absMask;
+ const int sign = aRep & signBit ? -1 : 1;
+ const int exponent = (aAbs >> significandBits) - exponentBias;
+ const rep_t significand = (aAbs & significandMask) | implicitBit;
+
+ // If 0 < exponent < significandBits, right shift to get the result.
+ if ((unsigned int)exponent < significandBits) {
+ return sign * (significand >> (significandBits - exponent));
+ }
+
+ // If exponent is negative, the result is zero.
+ else if (exponent < 0) {
+ return 0;
+ }
+
+ // If significandBits < exponent, left shift to get the result. This shift
+ // may end up being larger than the type width, which incurs undefined
+ // behavior, but the conversion itself is undefined in that case, so
+ // whatever the compiler decides to do is fine.
+ else {
+ return sign * (significand << (exponent - significandBits));
+ }
+}
diff --git a/contrib/compiler-rt/lib/fixsfti.c b/contrib/compiler-rt/lib/fixsfti.c
new file mode 100644
index 0000000..95992fe
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixsfti.c
@@ -0,0 +1,45 @@
+/* ===-- fixsfti.c - Implement __fixsfti -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixsfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in float is representable in ti_int (no range checking performed)
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+ti_int
+__fixsfti(float a)
+{
+ float_bits fb;
+ fb.f = a;
+ int e = ((fb.u & 0x7F800000) >> 23) - 127;
+ if (e < 0)
+ return 0;
+ ti_int s = (si_int)(fb.u & 0x80000000) >> 31;
+ ti_int r = (fb.u & 0x007FFFFF) | 0x00800000;
+ if (e > 23)
+ r <<= (e - 23);
+ else
+ r >>= (23 - e);
+ return (r ^ s) - s;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixunsdfdi.c b/contrib/compiler-rt/lib/fixunsdfdi.c
new file mode 100644
index 0000000..bdcee13
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsdfdi.c
@@ -0,0 +1,45 @@
+/* ===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsdfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * du_int is a 64 bit integral type
+ * value in double is representable in du_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+du_int
+__fixunsdfdi(double a)
+{
+ double_bits fb;
+ fb.f = a;
+ int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
+ if (e < 0 || (fb.u.s.high & 0x80000000))
+ return 0;
+ udwords r;
+ r.s.high = (fb.u.s.high & 0x000FFFFF) | 0x00100000;
+ r.s.low = fb.u.s.low;
+ if (e > 52)
+ r.all <<= (e - 52);
+ else
+ r.all >>= (52 - e);
+ return r.all;
+}
diff --git a/contrib/compiler-rt/lib/fixunsdfsi.c b/contrib/compiler-rt/lib/fixunsdfsi.c
new file mode 100644
index 0000000..a0cba79
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsdfsi.c
@@ -0,0 +1,42 @@
+/* ===-- fixunsdfsi.c - Implement __fixunsdfsi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsdfsi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned int, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in double is representable in su_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+su_int
+__fixunsdfsi(double a)
+{
+ double_bits fb;
+ fb.f = a;
+ int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
+ if (e < 0 || (fb.u.s.high & 0x80000000))
+ return 0;
+ return (
+ 0x80000000u |
+ ((fb.u.s.high & 0x000FFFFF) << 11) |
+ (fb.u.s.low >> 21)
+ ) >> (31 - e);
+}
diff --git a/contrib/compiler-rt/lib/fixunsdfti.c b/contrib/compiler-rt/lib/fixunsdfti.c
new file mode 100644
index 0000000..c1cd72d
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsdfti.c
@@ -0,0 +1,47 @@
+/* ===-- fixunsdfti.c - Implement __fixunsdfti -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsdfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * tu_int is a 64 bit integral type
+ * value in double is representable in tu_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+tu_int
+__fixunsdfti(double a)
+{
+ double_bits fb;
+ fb.f = a;
+ int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
+ if (e < 0 || (fb.u.s.high & 0x80000000))
+ return 0;
+ tu_int r = 0x0010000000000000uLL | (fb.u.all & 0x000FFFFFFFFFFFFFuLL);
+ if (e > 52)
+ r <<= (e - 52);
+ else
+ r >>= (52 - e);
+ return r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixunssfdi.c b/contrib/compiler-rt/lib/fixunssfdi.c
new file mode 100644
index 0000000..3837bd8
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunssfdi.c
@@ -0,0 +1,43 @@
+/* ===-- fixunssfdi.c - Implement __fixunssfdi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunssfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * du_int is a 64 bit integral type
+ * value in float is representable in du_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+du_int
+__fixunssfdi(float a)
+{
+ float_bits fb;
+ fb.f = a;
+ int e = ((fb.u & 0x7F800000) >> 23) - 127;
+ if (e < 0 || (fb.u & 0x80000000))
+ return 0;
+ du_int r = (fb.u & 0x007FFFFF) | 0x00800000;
+ if (e > 23)
+ r <<= (e - 23);
+ else
+ r >>= (23 - e);
+ return r;
+}
diff --git a/contrib/compiler-rt/lib/fixunssfsi.c b/contrib/compiler-rt/lib/fixunssfsi.c
new file mode 100644
index 0000000..a001cd4
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunssfsi.c
@@ -0,0 +1,43 @@
+/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunssfsi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned int, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * su_int is a 32 bit integral type
+ * value in float is representable in su_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+su_int
+__fixunssfsi(float a)
+{
+ float_bits fb;
+ fb.f = a;
+ int e = ((fb.u & 0x7F800000) >> 23) - 127;
+ if (e < 0 || (fb.u & 0x80000000))
+ return 0;
+ su_int r = (fb.u & 0x007FFFFF) | 0x00800000;
+ if (e > 23)
+ r <<= (e - 23);
+ else
+ r >>= (23 - e);
+ return r;
+}
diff --git a/contrib/compiler-rt/lib/fixunssfti.c b/contrib/compiler-rt/lib/fixunssfti.c
new file mode 100644
index 0000000..20b7e76
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunssfti.c
@@ -0,0 +1,47 @@
+/* ===-- fixunssfti.c - Implement __fixunssfti -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunssfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * tu_int is a 64 bit integral type
+ * value in float is representable in tu_int or is negative
+ * (no range checking performed)
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+tu_int
+__fixunssfti(float a)
+{
+ float_bits fb;
+ fb.f = a;
+ int e = ((fb.u & 0x7F800000) >> 23) - 127;
+ if (e < 0 || (fb.u & 0x80000000))
+ return 0;
+ tu_int r = (fb.u & 0x007FFFFF) | 0x00800000;
+ if (e > 23)
+ r <<= (e - 23);
+ else
+ r >>= (23 - e);
+ return r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixunsxfdi.c b/contrib/compiler-rt/lib/fixunsxfdi.c
new file mode 100644
index 0000000..872727b
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsxfdi.c
@@ -0,0 +1,44 @@
+/* ===-- fixunsxfdi.c - Implement __fixunsxfdi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsxfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
+ * du_int is a 64 bit integral type
+ * value in long double is representable in du_int or is negative
+ * (no range checking performed)
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+du_int
+__fixunsxfdi(long double a)
+{
+ long_double_bits fb;
+ fb.f = a;
+ int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
+ if (e < 0 || (fb.u.high.s.low & 0x00008000))
+ return 0;
+ return fb.u.low.all >> (63 - e);
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixunsxfsi.c b/contrib/compiler-rt/lib/fixunsxfsi.c
new file mode 100644
index 0000000..c9a607a
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsxfsi.c
@@ -0,0 +1,44 @@
+/* ===-- fixunsxfsi.c - Implement __fixunsxfsi -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsxfsi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned int, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
+ * su_int is a 32 bit integral type
+ * value in long double is representable in su_int or is negative
+ * (no range checking performed)
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+su_int
+__fixunsxfsi(long double a)
+{
+ long_double_bits fb;
+ fb.f = a;
+ int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
+ if (e < 0 || (fb.u.high.s.low & 0x00008000))
+ return 0;
+ return fb.u.low.s.high >> (31 - e);
+}
+
+#endif /* !_ARCH_PPC */
diff --git a/contrib/compiler-rt/lib/fixunsxfti.c b/contrib/compiler-rt/lib/fixunsxfti.c
new file mode 100644
index 0000000..d0bd512
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixunsxfti.c
@@ -0,0 +1,49 @@
+/* ===-- fixunsxfti.c - Implement __fixunsxfti -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixunsxfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a unsigned long long, rounding toward zero.
+ * Negative values all become zero.
+ */
+
+/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
+ * tu_int is a 64 bit integral type
+ * value in long double is representable in tu_int or is negative
+ * (no range checking performed)
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+tu_int
+__fixunsxfti(long double a)
+{
+ long_double_bits fb;
+ fb.f = a;
+ int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
+ if (e < 0 || (fb.u.high.s.low & 0x00008000))
+ return 0;
+ tu_int r = fb.u.low.all;
+ if (e > 63)
+ r <<= (e - 63);
+ else
+ r >>= (63 - e);
+ return r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fixxfdi.c b/contrib/compiler-rt/lib/fixxfdi.c
new file mode 100644
index 0000000..de6f818
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixxfdi.c
@@ -0,0 +1,44 @@
+/* ===-- fixxfdi.c - Implement __fixxfdi -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixxfdi for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
+ * su_int is a 32 bit integral type
+ * value in long double is representable in di_int (no range checking performed)
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+di_int
+__fixxfdi(long double a)
+{
+ long_double_bits fb;
+ fb.f = a;
+ int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
+ if (e < 0)
+ return 0;
+ di_int s = -(si_int)((fb.u.high.s.low & 0x00008000) >> 15);
+ di_int r = fb.u.low.all;
+ r = (du_int)r >> (63 - e);
+ return (r ^ s) - s;
+}
+
+#endif /* !_ARCH_PPC */
diff --git a/contrib/compiler-rt/lib/fixxfti.c b/contrib/compiler-rt/lib/fixxfti.c
new file mode 100644
index 0000000..c224801
--- /dev/null
+++ b/contrib/compiler-rt/lib/fixxfti.c
@@ -0,0 +1,47 @@
+/* ===-- fixxfti.c - Implement __fixxfti -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __fixxfti for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: convert a to a signed long long, rounding toward zero. */
+
+/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
+ * su_int is a 32 bit integral type
+ * value in long double is representable in ti_int (no range checking performed)
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+ti_int
+__fixxfti(long double a)
+{
+ long_double_bits fb;
+ fb.f = a;
+ int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
+ if (e < 0)
+ return 0;
+ ti_int s = -(si_int)((fb.u.high.s.low & 0x00008000) >> 15);
+ ti_int r = fb.u.low.all;
+ if (e > 63)
+ r <<= (e - 63);
+ else
+ r >>= (63 - e);
+ return (r ^ s) - s;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/floatdidf.c b/contrib/compiler-rt/lib/floatdidf.c
new file mode 100644
index 0000000..a0f501b
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatdidf.c
@@ -0,0 +1,107 @@
+/*===-- floatdidf.c - Implement __floatdidf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===
+ *
+ * This file implements __floatdidf for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a double, rounding toward even. */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * di_int is a 64 bit integral type
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; we'll set the inexact flag
+ * as a side-effect of this computation.
+ */
+#include <stdint.h>
+
+double
+__floatdidf(di_int a)
+{
+ static const double twop52 = 0x1.0p52;
+ static const double twop32 = 0x1.0p32;
+
+ union { int64_t x; double d; } low = { .d = twop52 };
+
+ const double high = (int32_t)(a >> 32) * twop32;
+ low.x |= a & INT64_C(0x00000000ffffffff);
+
+ const double result = (high - twop52) + low.d;
+ return result;
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no flags to
+ * set, and we don't want to code-gen to an unknown soft-float implementation.
+ */
+
+double
+__floatdidf(di_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(di_int) * CHAR_BIT;
+ const di_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int sd = N - __builtin_clzll(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > DBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit DBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit DBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case DBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case DBL_MANT_DIG + 2:
+ break;
+ default:
+ a = ((du_int)a >> (sd - (DBL_MANT_DIG+2))) |
+ ((a & ((du_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
+ if (a & ((du_int)1 << DBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (DBL_MANT_DIG - sd);
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ double_bits fb;
+ fb.u.high = ((su_int)s & 0x80000000) | /* sign */
+ ((e + 1023) << 20) | /* exponent */
+ ((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
+ fb.u.low = (su_int)a; /* mantissa-low */
+ return fb.f;
+}
+#endif
diff --git a/contrib/compiler-rt/lib/floatdisf.c b/contrib/compiler-rt/lib/floatdisf.c
new file mode 100644
index 0000000..1925f15
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatdisf.c
@@ -0,0 +1,79 @@
+/*===-- floatdisf.c - Implement __floatdisf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===
+ *
+ * This file implements __floatdisf for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a float, rounding toward even.*/
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * di_int is a 64 bit integral type
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+float
+__floatdisf(di_int a)
+{
+ if (a == 0)
+ return 0.0F;
+ const unsigned N = sizeof(di_int) * CHAR_BIT;
+ const di_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int sd = N - __builtin_clzll(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > FLT_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit FLT_MANT_DIG-1 bits to the right of 1
+ * Q = bit FLT_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case FLT_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case FLT_MANT_DIG + 2:
+ break;
+ default:
+ a = ((du_int)a >> (sd - (FLT_MANT_DIG+2))) |
+ ((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
+ if (a & ((du_int)1 << FLT_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (FLT_MANT_DIG - sd);
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ float_bits fb;
+ fb.u = ((su_int)s & 0x80000000) | /* sign */
+ ((e + 127) << 23) | /* exponent */
+ ((su_int)a & 0x007FFFFF); /* mantissa */
+ return fb.f;
+}
diff --git a/contrib/compiler-rt/lib/floatdixf.c b/contrib/compiler-rt/lib/floatdixf.c
new file mode 100644
index 0000000..bfda367
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatdixf.c
@@ -0,0 +1,46 @@
+/* ===-- floatdixf.c - Implement __floatdixf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatdixf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: convert a to a long double, rounding toward even. */
+
+/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
+ * di_int is a 64 bit integral type
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+long double
+__floatdixf(di_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(di_int) * CHAR_BIT;
+ const di_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int clz = __builtin_clzll(a);
+ int e = (N - 1) - clz ; /* exponent */
+ long_double_bits fb;
+ fb.u.high.s.low = ((su_int)s & 0x00008000) | /* sign */
+ (e + 16383); /* exponent */
+ fb.u.low.all = a << clz; /* mantissa */
+ return fb.f;
+}
+
+#endif /* !_ARCH_PPC */
diff --git a/contrib/compiler-rt/lib/floatsidf.c b/contrib/compiler-rt/lib/floatsidf.c
new file mode 100644
index 0000000..a13ab8f
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatsidf.c
@@ -0,0 +1,48 @@
+//===-- lib/floatsidf.c - integer -> double-precision conversion --*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements integer to double-precision conversion for the
+// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
+// mode.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __floatsidf(int a) {
+
+ const int aWidth = sizeof a * CHAR_BIT;
+
+ // Handle zero as a special case to protect clz
+ if (a == 0)
+ return fromRep(0);
+
+ // All other cases begin by extracting the sign and absolute value of a
+ rep_t sign = 0;
+ if (a < 0) {
+ sign = signBit;
+ a = -a;
+ }
+
+ // Exponent of (fp_t)a is the width of abs(a).
+ const int exponent = (aWidth - 1) - __builtin_clz(a);
+ rep_t result;
+
+ // Shift a into the significand field and clear the implicit bit. Extra
+ // cast to unsigned int is necessary to get the correct behavior for
+ // the input INT_MIN.
+ const int shift = significandBits - exponent;
+ result = (rep_t)(unsigned int)a << shift ^ implicitBit;
+
+ // Insert the exponent
+ result += (rep_t)(exponent + exponentBias) << significandBits;
+ // Insert the sign bit and return
+ return fromRep(result | sign);
+}
diff --git a/contrib/compiler-rt/lib/floatsisf.c b/contrib/compiler-rt/lib/floatsisf.c
new file mode 100644
index 0000000..4a62975
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatsisf.c
@@ -0,0 +1,54 @@
+//===-- lib/floatsisf.c - integer -> single-precision conversion --*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements integer to single-precision conversion for the
+// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
+// mode.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __floatsisf(int a) {
+
+ const int aWidth = sizeof a * CHAR_BIT;
+
+ // Handle zero as a special case to protect clz
+ if (a == 0)
+ return fromRep(0);
+
+ // All other cases begin by extracting the sign and absolute value of a
+ rep_t sign = 0;
+ if (a < 0) {
+ sign = signBit;
+ a = -a;
+ }
+
+ // Exponent of (fp_t)a is the width of abs(a).
+ const int exponent = (aWidth - 1) - __builtin_clz(a);
+ rep_t result;
+
+ // Shift a into the significand field, rounding if it is a right-shift
+ if (exponent <= significandBits) {
+ const int shift = significandBits - exponent;
+ result = (rep_t)a << shift ^ implicitBit;
+ } else {
+ const int shift = exponent - significandBits;
+ result = (rep_t)a >> shift ^ implicitBit;
+ rep_t round = (rep_t)a << (typeWidth - shift);
+ if (round > signBit) result++;
+ if (round == signBit) result += result & 1;
+ }
+
+ // Insert the exponent
+ result += (rep_t)(exponent + exponentBias) << significandBits;
+ // Insert the sign bit and return
+ return fromRep(result | sign);
+}
diff --git a/contrib/compiler-rt/lib/floattidf.c b/contrib/compiler-rt/lib/floattidf.c
new file mode 100644
index 0000000..274f585
--- /dev/null
+++ b/contrib/compiler-rt/lib/floattidf.c
@@ -0,0 +1,86 @@
+/* ===-- floattidf.c - Implement __floattidf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floattidf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a double, rounding toward even.*/
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * ti_int is a 128 bit integral type
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+si_int __clzti2(ti_int a);
+
+double
+__floattidf(ti_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(ti_int) * CHAR_BIT;
+ const ti_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > DBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit DBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit DBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case DBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case DBL_MANT_DIG + 2:
+ break;
+ default:
+ a = ((tu_int)a >> (sd - (DBL_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << DBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (DBL_MANT_DIG - sd);
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ double_bits fb;
+ fb.u.s.high = ((su_int)s & 0x80000000) | /* sign */
+ ((e + 1023) << 20) | /* exponent */
+ ((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
+ fb.u.s.low = (su_int)a; /* mantissa-low */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/floattisf.c b/contrib/compiler-rt/lib/floattisf.c
new file mode 100644
index 0000000..72f3748
--- /dev/null
+++ b/contrib/compiler-rt/lib/floattisf.c
@@ -0,0 +1,85 @@
+/* ===-- floattisf.c - Implement __floattisf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floattisf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a float, rounding toward even. */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * ti_int is a 128 bit integral type
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+si_int __clzti2(ti_int a);
+
+float
+__floattisf(ti_int a)
+{
+ if (a == 0)
+ return 0.0F;
+ const unsigned N = sizeof(ti_int) * CHAR_BIT;
+ const ti_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > FLT_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit FLT_MANT_DIG-1 bits to the right of 1
+ * Q = bit FLT_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case FLT_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case FLT_MANT_DIG + 2:
+ break;
+ default:
+ a = ((tu_int)a >> (sd - (FLT_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << FLT_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (FLT_MANT_DIG - sd);
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ float_bits fb;
+ fb.u = ((su_int)s & 0x80000000) | /* sign */
+ ((e + 127) << 23) | /* exponent */
+ ((su_int)a & 0x007FFFFF); /* mantissa */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/floattixf.c b/contrib/compiler-rt/lib/floattixf.c
new file mode 100644
index 0000000..77d9060
--- /dev/null
+++ b/contrib/compiler-rt/lib/floattixf.c
@@ -0,0 +1,87 @@
+/* ===-- floattixf.c - Implement __floattixf -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floattixf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a long double, rounding toward even. */
+
+/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
+ * ti_int is a 128 bit integral type
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+si_int __clzti2(ti_int a);
+
+long double
+__floattixf(ti_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(ti_int) * CHAR_BIT;
+ const ti_int s = a >> (N-1);
+ a = (a ^ s) - s;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > LDBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit LDBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit LDBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case LDBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case LDBL_MANT_DIG + 2:
+ break;
+ default:
+ a = ((tu_int)a >> (sd - (LDBL_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << LDBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to LDBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (LDBL_MANT_DIG - sd);
+ /* a is now rounded to LDBL_MANT_DIG bits */
+ }
+ long_double_bits fb;
+ fb.u.high.s.low = ((su_int)s & 0x8000) | /* sign */
+ (e + 16383); /* exponent */
+ fb.u.low.all = (du_int)a; /* mantissa */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/floatundidf.c b/contrib/compiler-rt/lib/floatundidf.c
new file mode 100644
index 0000000..1f304c5
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatundidf.c
@@ -0,0 +1,107 @@
+/* ===-- floatundidf.c - Implement __floatundidf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatundidf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a double, rounding toward even. */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * du_int is a 64 bit integral type
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+#ifndef __SOFT_FP__
+/* Support for systems that have hardware floating-point; we'll set the inexact flag
+ * as a side-effect of this computation.
+ */
+
+#include <stdint.h>
+
+double
+__floatundidf(du_int a)
+{
+ static const double twop52 = 0x1.0p52;
+ static const double twop84 = 0x1.0p84;
+ static const double twop84_plus_twop52 = 0x1.00000001p84;
+
+ union { uint64_t x; double d; } high = { .d = twop84 };
+ union { uint64_t x; double d; } low = { .d = twop52 };
+
+ high.x |= a >> 32;
+ low.x |= a & UINT64_C(0x00000000ffffffff);
+
+ const double result = (high.d - twop84_plus_twop52) + low.d;
+ return result;
+}
+
+#else
+/* Support for systems that don't have hardware floating-point; there are no flags to
+ * set, and we don't want to code-gen to an unknown soft-float implementation.
+ */
+
+double
+__floatundidf(du_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(du_int) * CHAR_BIT;
+ int sd = N - __builtin_clzll(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > DBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit DBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit DBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case DBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case DBL_MANT_DIG + 2:
+ break;
+ default:
+ a = (a >> (sd - (DBL_MANT_DIG+2))) |
+ ((a & ((du_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
+ if (a & ((du_int)1 << DBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (DBL_MANT_DIG - sd);
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ double_bits fb;
+ fb.u.high = ((e + 1023) << 20) | /* exponent */
+ ((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
+ fb.u.low = (su_int)a; /* mantissa-low */
+ return fb.f;
+}
+#endif
diff --git a/contrib/compiler-rt/lib/floatundisf.c b/contrib/compiler-rt/lib/floatundisf.c
new file mode 100644
index 0000000..79b4b82
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatundisf.c
@@ -0,0 +1,76 @@
+/*===-- floatundisf.c - Implement __floatundisf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatundisf for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a float, rounding toward even. */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * du_int is a 64 bit integral type
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+float
+__floatundisf(du_int a)
+{
+ if (a == 0)
+ return 0.0F;
+ const unsigned N = sizeof(du_int) * CHAR_BIT;
+ int sd = N - __builtin_clzll(a); /* number of significant digits */
+ int e = sd - 1; /* 8 exponent */
+ if (sd > FLT_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit FLT_MANT_DIG-1 bits to the right of 1
+ * Q = bit FLT_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case FLT_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case FLT_MANT_DIG + 2:
+ break;
+ default:
+ a = (a >> (sd - (FLT_MANT_DIG+2))) |
+ ((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
+ if (a & ((du_int)1 << FLT_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (FLT_MANT_DIG - sd);
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ float_bits fb;
+ fb.u = ((e + 127) << 23) | /* exponent */
+ ((su_int)a & 0x007FFFFF); /* mantissa */
+ return fb.f;
+}
diff --git a/contrib/compiler-rt/lib/floatundixf.c b/contrib/compiler-rt/lib/floatundixf.c
new file mode 100644
index 0000000..bc9582f
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatundixf.c
@@ -0,0 +1,42 @@
+/* ===-- floatundixf.c - Implement __floatundixf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatundixf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: convert a to a long double, rounding toward even. */
+
+/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
+ * du_int is a 64 bit integral type
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+long double
+__floatundixf(du_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(du_int) * CHAR_BIT;
+ int clz = __builtin_clzll(a);
+ int e = (N - 1) - clz ; /* exponent */
+ long_double_bits fb;
+ fb.u.high.s.low = (e + 16383); /* exponent */
+ fb.u.low.all = a << clz; /* mantissa */
+ return fb.f;
+}
+
+#endif /* _ARCH_PPC */
diff --git a/contrib/compiler-rt/lib/floatunsidf.c b/contrib/compiler-rt/lib/floatunsidf.c
new file mode 100644
index 0000000..05242c1
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatunsidf.c
@@ -0,0 +1,37 @@
+//===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements unsigned integer to double-precision conversion for the
+// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
+// mode.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __floatunsidf(unsigned int a) {
+
+ const int aWidth = sizeof a * CHAR_BIT;
+
+ // Handle zero as a special case to protect clz
+ if (a == 0) return fromRep(0);
+
+ // Exponent of (fp_t)a is the width of abs(a).
+ const int exponent = (aWidth - 1) - __builtin_clz(a);
+ rep_t result;
+
+ // Shift a into the significand field and clear the implicit bit.
+ const int shift = significandBits - exponent;
+ result = (rep_t)a << shift ^ implicitBit;
+
+ // Insert the exponent
+ result += (rep_t)(exponent + exponentBias) << significandBits;
+ return fromRep(result);
+}
diff --git a/contrib/compiler-rt/lib/floatunsisf.c b/contrib/compiler-rt/lib/floatunsisf.c
new file mode 100644
index 0000000..31c0644
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatunsisf.c
@@ -0,0 +1,45 @@
+//===-- lib/floatunsisf.c - uint -> single-precision conversion ---*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements unsigned integer to single-precision conversion for the
+// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
+// mode.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __floatunsisf(unsigned int a) {
+
+ const int aWidth = sizeof a * CHAR_BIT;
+
+ // Handle zero as a special case to protect clz
+ if (a == 0) return fromRep(0);
+
+ // Exponent of (fp_t)a is the width of abs(a).
+ const int exponent = (aWidth - 1) - __builtin_clz(a);
+ rep_t result;
+
+ // Shift a into the significand field, rounding if it is a right-shift
+ if (exponent <= significandBits) {
+ const int shift = significandBits - exponent;
+ result = (rep_t)a << shift ^ implicitBit;
+ } else {
+ const int shift = exponent - significandBits;
+ result = (rep_t)a >> shift ^ implicitBit;
+ rep_t round = (rep_t)a << (typeWidth - shift);
+ if (round > signBit) result++;
+ if (round == signBit) result += result & 1;
+ }
+
+ // Insert the exponent
+ result += (rep_t)(exponent + exponentBias) << significandBits;
+ return fromRep(result);
+}
diff --git a/contrib/compiler-rt/lib/floatuntidf.c b/contrib/compiler-rt/lib/floatuntidf.c
new file mode 100644
index 0000000..51d8b28
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatuntidf.c
@@ -0,0 +1,83 @@
+/* ===-- floatuntidf.c - Implement __floatuntidf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatuntidf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a double, rounding toward even. */
+
+/* Assumption: double is a IEEE 64 bit floating point type
+ * tu_int is a 128 bit integral type
+ */
+
+/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
+
+si_int __clzti2(ti_int a);
+
+double
+__floatuntidf(tu_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(tu_int) * CHAR_BIT;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > DBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit DBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit DBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case DBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case DBL_MANT_DIG + 2:
+ break;
+ default:
+ a = (a >> (sd - (DBL_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << DBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (DBL_MANT_DIG - sd);
+ /* a is now rounded to DBL_MANT_DIG bits */
+ }
+ double_bits fb;
+ fb.u.s.high = ((e + 1023) << 20) | /* exponent */
+ ((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
+ fb.u.s.low = (su_int)a; /* mantissa-low */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/floatuntisf.c b/contrib/compiler-rt/lib/floatuntisf.c
new file mode 100644
index 0000000..328f39b
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatuntisf.c
@@ -0,0 +1,82 @@
+/* ===-- floatuntisf.c - Implement __floatuntisf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatuntisf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a float, rounding toward even. */
+
+/* Assumption: float is a IEEE 32 bit floating point type
+ * tu_int is a 128 bit integral type
+ */
+
+/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
+
+si_int __clzti2(ti_int a);
+
+float
+__floatuntisf(tu_int a)
+{
+ if (a == 0)
+ return 0.0F;
+ const unsigned N = sizeof(tu_int) * CHAR_BIT;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > FLT_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit FLT_MANT_DIG-1 bits to the right of 1
+ * Q = bit FLT_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case FLT_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case FLT_MANT_DIG + 2:
+ break;
+ default:
+ a = (a >> (sd - (FLT_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << FLT_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (FLT_MANT_DIG - sd);
+ /* a is now rounded to FLT_MANT_DIG bits */
+ }
+ float_bits fb;
+ fb.u = ((e + 127) << 23) | /* exponent */
+ ((su_int)a & 0x007FFFFF); /* mantissa */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/floatuntixf.c b/contrib/compiler-rt/lib/floatuntixf.c
new file mode 100644
index 0000000..e82d0c1
--- /dev/null
+++ b/contrib/compiler-rt/lib/floatuntixf.c
@@ -0,0 +1,84 @@
+/* ===-- floatuntixf.c - Implement __floatuntixf ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __floatuntixf for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <float.h>
+
+/* Returns: convert a to a long double, rounding toward even. */
+
+/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
+ * tu_int is a 128 bit integral type
+ */
+
+/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
+ * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
+ */
+
+si_int __clzti2(ti_int a);
+
+long double
+__floatuntixf(tu_int a)
+{
+ if (a == 0)
+ return 0.0;
+ const unsigned N = sizeof(tu_int) * CHAR_BIT;
+ int sd = N - __clzti2(a); /* number of significant digits */
+ int e = sd - 1; /* exponent */
+ if (sd > LDBL_MANT_DIG)
+ {
+ /* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
+ * finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
+ * 12345678901234567890123456
+ * 1 = msb 1 bit
+ * P = bit LDBL_MANT_DIG-1 bits to the right of 1
+ * Q = bit LDBL_MANT_DIG bits to the right of 1
+ * R = "or" of all bits to the right of Q
+ */
+ switch (sd)
+ {
+ case LDBL_MANT_DIG + 1:
+ a <<= 1;
+ break;
+ case LDBL_MANT_DIG + 2:
+ break;
+ default:
+ a = (a >> (sd - (LDBL_MANT_DIG+2))) |
+ ((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG+2) - sd))) != 0);
+ };
+ /* finish: */
+ a |= (a & 4) != 0; /* Or P into R */
+ ++a; /* round - this step may add a significant bit */
+ a >>= 2; /* dump Q and R */
+ /* a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits */
+ if (a & ((tu_int)1 << LDBL_MANT_DIG))
+ {
+ a >>= 1;
+ ++e;
+ }
+ /* a is now rounded to LDBL_MANT_DIG bits */
+ }
+ else
+ {
+ a <<= (LDBL_MANT_DIG - sd);
+ /* a is now rounded to LDBL_MANT_DIG bits */
+ }
+ long_double_bits fb;
+ fb.u.high.s.low = (e + 16383); /* exponent */
+ fb.u.low.all = (du_int)a; /* mantissa */
+ return fb.f;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/fp_lib.h b/contrib/compiler-rt/lib/fp_lib.h
new file mode 100644
index 0000000..eac670d
--- /dev/null
+++ b/contrib/compiler-rt/lib/fp_lib.h
@@ -0,0 +1,143 @@
+//===-- lib/fp_lib.h - Floating-point utilities -------------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a configuration header for soft-float routines in compiler-rt.
+// This file does not provide any part of the compiler-rt interface, but defines
+// many useful constants and utility routines that are used in the
+// implementation of the soft-float routines in compiler-rt.
+//
+// Assumes that float and double correspond to the IEEE-754 binary32 and
+// binary64 types, respectively, and that integer endianness matches floating
+// point endianness on the target platform.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FP_LIB_HEADER
+#define FP_LIB_HEADER
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <limits.h>
+
+#if defined SINGLE_PRECISION
+
+typedef uint32_t rep_t;
+typedef int32_t srep_t;
+typedef float fp_t;
+#define REP_C UINT32_C
+#define significandBits 23
+
+static inline int rep_clz(rep_t a) {
+ return __builtin_clz(a);
+}
+
+// 32x32 --> 64 bit multiply
+static inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
+ const uint64_t product = (uint64_t)a*b;
+ *hi = product >> 32;
+ *lo = product;
+}
+
+#elif defined DOUBLE_PRECISION
+
+typedef uint64_t rep_t;
+typedef int64_t srep_t;
+typedef double fp_t;
+#define REP_C UINT64_C
+#define significandBits 52
+
+static inline int rep_clz(rep_t a) {
+#if defined __LP64__
+ return __builtin_clzl(a);
+#else
+ if (a & REP_C(0xffffffff00000000))
+ return __builtin_clz(a >> 32);
+ else
+ return 32 + __builtin_clz(a & REP_C(0xffffffff));
+#endif
+}
+
+#define loWord(a) (a & 0xffffffffU)
+#define hiWord(a) (a >> 32)
+
+// 64x64 -> 128 wide multiply for platforms that don't have such an operation;
+// many 64-bit platforms have this operation, but they tend to have hardware
+// floating-point, so we don't bother with a special case for them here.
+static inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
+ // Each of the component 32x32 -> 64 products
+ const uint64_t plolo = loWord(a) * loWord(b);
+ const uint64_t plohi = loWord(a) * hiWord(b);
+ const uint64_t philo = hiWord(a) * loWord(b);
+ const uint64_t phihi = hiWord(a) * hiWord(b);
+ // Sum terms that contribute to lo in a way that allows us to get the carry
+ const uint64_t r0 = loWord(plolo);
+ const uint64_t r1 = hiWord(plolo) + loWord(plohi) + loWord(philo);
+ *lo = r0 + (r1 << 32);
+ // Sum terms contributing to hi with the carry from lo
+ *hi = hiWord(plohi) + hiWord(philo) + hiWord(r1) + phihi;
+}
+
+#else
+#error Either SINGLE_PRECISION or DOUBLE_PRECISION must be defined.
+#endif
+
+#define typeWidth (sizeof(rep_t)*CHAR_BIT)
+#define exponentBits (typeWidth - significandBits - 1)
+#define maxExponent ((1 << exponentBits) - 1)
+#define exponentBias (maxExponent >> 1)
+
+#define implicitBit (REP_C(1) << significandBits)
+#define significandMask (implicitBit - 1U)
+#define signBit (REP_C(1) << (significandBits + exponentBits))
+#define absMask (signBit - 1U)
+#define exponentMask (absMask ^ significandMask)
+#define oneRep ((rep_t)exponentBias << significandBits)
+#define infRep exponentMask
+#define quietBit (implicitBit >> 1)
+#define qnanRep (exponentMask | quietBit)
+
+static inline rep_t toRep(fp_t x) {
+ const union { fp_t f; rep_t i; } rep = {.f = x};
+ return rep.i;
+}
+
+static inline fp_t fromRep(rep_t x) {
+ const union { fp_t f; rep_t i; } rep = {.i = x};
+ return rep.f;
+}
+
+static inline int normalize(rep_t *significand) {
+ const int shift = rep_clz(*significand) - rep_clz(implicitBit);
+ *significand <<= shift;
+ return 1 - shift;
+}
+
+static inline void wideLeftShift(rep_t *hi, rep_t *lo, int count) {
+ *hi = *hi << count | *lo >> (typeWidth - count);
+ *lo = *lo << count;
+}
+
+static inline void wideRightShiftWithSticky(rep_t *hi, rep_t *lo, int count) {
+ if (count < typeWidth) {
+ const bool sticky = *lo << (typeWidth - count);
+ *lo = *hi << (typeWidth - count) | *lo >> count | sticky;
+ *hi = *hi >> count;
+ }
+ else if (count < 2*typeWidth) {
+ const bool sticky = *hi << (2*typeWidth - count) | *lo;
+ *lo = *hi >> (count - typeWidth) | sticky;
+ *hi = 0;
+ } else {
+ const bool sticky = *hi | *lo;
+ *lo = sticky;
+ *hi = 0;
+ }
+}
+
+#endif // FP_LIB_HEADER
diff --git a/contrib/compiler-rt/lib/gcc_personality_v0.c b/contrib/compiler-rt/lib/gcc_personality_v0.c
new file mode 100644
index 0000000..5940190
--- /dev/null
+++ b/contrib/compiler-rt/lib/gcc_personality_v0.c
@@ -0,0 +1,251 @@
+/* ===-- gcc_personality_v0.c - Implement __gcc_personality_v0 -------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "int_lib.h"
+
+/*
+ * _Unwind_* stuff based on C++ ABI public documentation
+ * http://refspecs.freestandards.org/abi-eh-1.21.html
+ */
+
+typedef enum {
+ _URC_NO_REASON = 0,
+ _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
+ _URC_FATAL_PHASE2_ERROR = 2,
+ _URC_FATAL_PHASE1_ERROR = 3,
+ _URC_NORMAL_STOP = 4,
+ _URC_END_OF_STACK = 5,
+ _URC_HANDLER_FOUND = 6,
+ _URC_INSTALL_CONTEXT = 7,
+ _URC_CONTINUE_UNWIND = 8
+} _Unwind_Reason_Code;
+
+typedef enum {
+ _UA_SEARCH_PHASE = 1,
+ _UA_CLEANUP_PHASE = 2,
+ _UA_HANDLER_FRAME = 4,
+ _UA_FORCE_UNWIND = 8,
+ _UA_END_OF_STACK = 16
+} _Unwind_Action;
+
+typedef struct _Unwind_Context* _Unwind_Context_t;
+
+struct _Unwind_Exception {
+ uint64_t exception_class;
+ void (*exception_cleanup)(_Unwind_Reason_Code reason,
+ struct _Unwind_Exception* exc);
+ uintptr_t private_1;
+ uintptr_t private_2;
+};
+
+extern const uint8_t* _Unwind_GetLanguageSpecificData(_Unwind_Context_t c);
+extern void _Unwind_SetGR(_Unwind_Context_t c, int i, uintptr_t n);
+extern void _Unwind_SetIP(_Unwind_Context_t, uintptr_t new_value);
+extern uintptr_t _Unwind_GetIP(_Unwind_Context_t context);
+extern uintptr_t _Unwind_GetRegionStart(_Unwind_Context_t context);
+
+
+/*
+ * Pointer encodings documented at:
+ * http://refspecs.freestandards.org/LSB_1.3.0/gLSB/gLSB/ehframehdr.html
+ */
+
+#define DW_EH_PE_omit 0xff /* no data follows */
+
+#define DW_EH_PE_absptr 0x00
+#define DW_EH_PE_uleb128 0x01
+#define DW_EH_PE_udata2 0x02
+#define DW_EH_PE_udata4 0x03
+#define DW_EH_PE_udata8 0x04
+#define DW_EH_PE_sleb128 0x09
+#define DW_EH_PE_sdata2 0x0A
+#define DW_EH_PE_sdata4 0x0B
+#define DW_EH_PE_sdata8 0x0C
+
+#define DW_EH_PE_pcrel 0x10
+#define DW_EH_PE_textrel 0x20
+#define DW_EH_PE_datarel 0x30
+#define DW_EH_PE_funcrel 0x40
+#define DW_EH_PE_aligned 0x50
+#define DW_EH_PE_indirect 0x80 /* gcc extension */
+
+
+
+/* read a uleb128 encoded value and advance pointer */
+static uintptr_t readULEB128(const uint8_t** data)
+{
+ uintptr_t result = 0;
+ uintptr_t shift = 0;
+ unsigned char byte;
+ const uint8_t* p = *data;
+ do {
+ byte = *p++;
+ result |= (byte & 0x7f) << shift;
+ shift += 7;
+ } while (byte & 0x80);
+ *data = p;
+ return result;
+}
+
+/* read a pointer encoded value and advance pointer */
+static uintptr_t readEncodedPointer(const uint8_t** data, uint8_t encoding)
+{
+ const uint8_t* p = *data;
+ uintptr_t result = 0;
+
+ if ( encoding == DW_EH_PE_omit )
+ return 0;
+
+ /* first get value */
+ switch (encoding & 0x0F) {
+ case DW_EH_PE_absptr:
+ result = *((uintptr_t*)p);
+ p += sizeof(uintptr_t);
+ break;
+ case DW_EH_PE_uleb128:
+ result = readULEB128(&p);
+ break;
+ case DW_EH_PE_udata2:
+ result = *((uint16_t*)p);
+ p += sizeof(uint16_t);
+ break;
+ case DW_EH_PE_udata4:
+ result = *((uint32_t*)p);
+ p += sizeof(uint32_t);
+ break;
+ case DW_EH_PE_udata8:
+ result = *((uint64_t*)p);
+ p += sizeof(uint64_t);
+ break;
+ case DW_EH_PE_sdata2:
+ result = *((int16_t*)p);
+ p += sizeof(int16_t);
+ break;
+ case DW_EH_PE_sdata4:
+ result = *((int32_t*)p);
+ p += sizeof(int32_t);
+ break;
+ case DW_EH_PE_sdata8:
+ result = *((int64_t*)p);
+ p += sizeof(int64_t);
+ break;
+ case DW_EH_PE_sleb128:
+ default:
+ /* not supported */
+ compilerrt_abort();
+ break;
+ }
+
+ /* then add relative offset */
+ switch ( encoding & 0x70 ) {
+ case DW_EH_PE_absptr:
+ /* do nothing */
+ break;
+ case DW_EH_PE_pcrel:
+ result += (uintptr_t)(*data);
+ break;
+ case DW_EH_PE_textrel:
+ case DW_EH_PE_datarel:
+ case DW_EH_PE_funcrel:
+ case DW_EH_PE_aligned:
+ default:
+ /* not supported */
+ compilerrt_abort();
+ break;
+ }
+
+ /* then apply indirection */
+ if (encoding & DW_EH_PE_indirect) {
+ result = *((uintptr_t*)result);
+ }
+
+ *data = p;
+ return result;
+}
+
+
+/*
+ * The C compiler makes references to __gcc_personality_v0 in
+ * the dwarf unwind information for translation units that use
+ * __attribute__((cleanup(xx))) on local variables.
+ * This personality routine is called by the system unwinder
+ * on each frame as the stack is unwound during a C++ exception
+ * throw through a C function compiled with -fexceptions.
+ */
+#if __arm__
+// the setjump-longjump based exceptions personality routine has a different name
+_Unwind_Reason_Code __gcc_personality_sj0(int version, _Unwind_Action actions,
+ uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
+ _Unwind_Context_t context)
+#else
+_Unwind_Reason_Code __gcc_personality_v0(int version, _Unwind_Action actions,
+ uint64_t exceptionClass, struct _Unwind_Exception* exceptionObject,
+ _Unwind_Context_t context)
+#endif
+{
+ /* Since C does not have catch clauses, there is nothing to do during */
+ /* phase 1 (the search phase). */
+ if ( actions & _UA_SEARCH_PHASE )
+ return _URC_CONTINUE_UNWIND;
+
+ /* There is nothing to do if there is no LSDA for this frame. */
+ const uint8_t* lsda = _Unwind_GetLanguageSpecificData(context);
+ if ( lsda == NULL )
+ return _URC_CONTINUE_UNWIND;
+
+ uintptr_t pc = _Unwind_GetIP(context)-1;
+ uintptr_t funcStart = _Unwind_GetRegionStart(context);
+ uintptr_t pcOffset = pc - funcStart;
+
+ /* Parse LSDA header. */
+ uint8_t lpStartEncoding = *lsda++;
+ if (lpStartEncoding != DW_EH_PE_omit) {
+ readEncodedPointer(&lsda, lpStartEncoding);
+ }
+ uint8_t ttypeEncoding = *lsda++;
+ if (ttypeEncoding != DW_EH_PE_omit) {
+ readULEB128(&lsda);
+ }
+ /* Walk call-site table looking for range that includes current PC. */
+ uint8_t callSiteEncoding = *lsda++;
+ uint32_t callSiteTableLength = readULEB128(&lsda);
+ const uint8_t* callSiteTableStart = lsda;
+ const uint8_t* callSiteTableEnd = callSiteTableStart + callSiteTableLength;
+ const uint8_t* p=callSiteTableStart;
+ while (p < callSiteTableEnd) {
+ uintptr_t start = readEncodedPointer(&p, callSiteEncoding);
+ uintptr_t length = readEncodedPointer(&p, callSiteEncoding);
+ uintptr_t landingPad = readEncodedPointer(&p, callSiteEncoding);
+ readULEB128(&p); /* action value not used for C code */
+ if ( landingPad == 0 )
+ continue; /* no landing pad for this entry */
+ if ( (start <= pcOffset) && (pcOffset < (start+length)) ) {
+ /* Found landing pad for the PC.
+ * Set Instruction Pointer to so we re-enter function
+ * at landing pad. The landing pad is created by the compiler
+ * to take two parameters in registers.
+ */
+ _Unwind_SetGR(context, __builtin_eh_return_data_regno(0),
+ (uintptr_t)exceptionObject);
+ _Unwind_SetGR(context, __builtin_eh_return_data_regno(1), 0);
+ _Unwind_SetIP(context, funcStart+landingPad);
+ return _URC_INSTALL_CONTEXT;
+ }
+ }
+
+ /* No landing pad found, continue unwinding. */
+ return _URC_CONTINUE_UNWIND;
+}
+
diff --git a/contrib/compiler-rt/lib/i386/ashldi3.S b/contrib/compiler-rt/lib/i386/ashldi3.S
new file mode 100644
index 0000000..af6f98b
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/ashldi3.S
@@ -0,0 +1,56 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __ashldi3(di_int input, int count);
+
+// This routine has some extra memory traffic, loading the 64-bit input via two
+// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
+// store. This is to avoid a write-small, read-large stall.
+// However, if callers of this routine can be safely assumed to store the argument
+// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
+// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
+
+#ifdef __i386__
+#ifdef __SSE2__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__ashldi3)
+ movd 12(%esp), %xmm2 // Load count
+#ifndef TRUST_CALLERS_USE_64_BIT_STORES
+ movd 4(%esp), %xmm0
+ movd 8(%esp), %xmm1
+ punpckldq %xmm1, %xmm0 // Load input
+#else
+ movq 4(%esp), %xmm0 // Load input
+#endif
+ psllq %xmm2, %xmm0 // shift input by count
+ movd %xmm0, %eax
+ psrlq $32, %xmm0
+ movd %xmm0, %edx
+ ret
+
+#else // Use GPRs instead of SSE2 instructions, if they aren't available.
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__ashldi3)
+ movl 12(%esp), %ecx // Load count
+ movl 8(%esp), %edx // Load high
+ movl 4(%esp), %eax // Load low
+
+ testl $0x20, %ecx // If count >= 32
+ jnz 1f // goto 1
+ shldl %cl, %eax, %edx // left shift high by count
+ shll %cl, %eax // left shift low by count
+ ret
+
+1: movl %eax, %edx // Move low to high
+ xorl %eax, %eax // clear low
+ shll %cl, %edx // shift high by count - 32
+ ret
+
+#endif // __SSE2__
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/ashrdi3.S b/contrib/compiler-rt/lib/i386/ashrdi3.S
new file mode 100644
index 0000000..346f9b1
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/ashrdi3.S
@@ -0,0 +1,67 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __ashrdi3(di_int input, int count);
+
+#ifdef __i386__
+#ifdef __SSE2__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
+ movd 12(%esp), %xmm2 // Load count
+ movl 8(%esp), %eax
+#ifndef TRUST_CALLERS_USE_64_BIT_STORES
+ movd 4(%esp), %xmm0
+ movd 8(%esp), %xmm1
+ punpckldq %xmm1, %xmm0 // Load input
+#else
+ movq 4(%esp), %xmm0 // Load input
+#endif
+
+ psrlq %xmm2, %xmm0 // unsigned shift input by count
+
+ testl %eax, %eax // check the sign-bit of the input
+ jns 1f // early out for positive inputs
+
+ // If the input is negative, we need to construct the shifted sign bit
+ // to or into the result, as xmm does not have a signed right shift.
+ pcmpeqb %xmm1, %xmm1 // -1ULL
+ psrlq $58, %xmm1 // 0x3f
+ pandn %xmm1, %xmm2 // 63 - count
+ pcmpeqb %xmm1, %xmm1 // -1ULL
+ psubq %xmm1, %xmm2 // 64 - count
+ psllq %xmm2, %xmm1 // -1 << (64 - count) = leading sign bits
+ por %xmm1, %xmm0
+
+ // Move the result back to the general purpose registers and return
+1: movd %xmm0, %eax
+ psrlq $32, %xmm0
+ movd %xmm0, %edx
+ ret
+
+#else // Use GPRs instead of SSE2 instructions, if they aren't available.
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__ashrdi3)
+ movl 12(%esp), %ecx // Load count
+ movl 8(%esp), %edx // Load high
+ movl 4(%esp), %eax // Load low
+
+ testl $0x20, %ecx // If count >= 32
+ jnz 1f // goto 1
+
+ shrdl %cl, %edx, %eax // right shift low by count
+ sarl %cl, %edx // right shift high by count
+ ret
+
+1: movl %edx, %eax // Move high to low
+ sarl $31, %edx // clear high
+ sarl %cl, %eax // shift low by count - 32
+ ret
+
+#endif // __SSE2__
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/divdi3.S b/contrib/compiler-rt/lib/i386/divdi3.S
new file mode 100644
index 0000000..5ad530c
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/divdi3.S
@@ -0,0 +1,161 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __divdi3(di_int a, di_int b);
+
+// result = a / b.
+// both inputs and the output are 64-bit signed integers.
+// This will do whatever the underlying hardware is set to do on division by zero.
+// No other exceptions are generated, as the divide cannot overflow.
+//
+// This is targeted at 32-bit x86 *only*, as this can be done directly in hardware
+// on x86_64. The performance goal is ~40 cycles per divide, which is faster than
+// currently possible via simulation of integer divides on the x87 unit.
+//
+// Stephen Canon, December 2008
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__divdi3)
+
+/* This is currently implemented by wrapping the unsigned divide up in an absolute
+ value, then restoring the correct sign at the end of the computation. This could
+ certainly be improved upon. */
+
+ pushl %esi
+ movl 20(%esp), %edx // high word of b
+ movl 16(%esp), %eax // low word of b
+ movl %edx, %ecx
+ sarl $31, %ecx // (b < 0) ? -1 : 0
+ xorl %ecx, %eax
+ xorl %ecx, %edx // EDX:EAX = (b < 0) ? not(b) : b
+ subl %ecx, %eax
+ sbbl %ecx, %edx // EDX:EAX = abs(b)
+ movl %edx, 20(%esp)
+ movl %eax, 16(%esp) // store abs(b) back to stack
+ movl %ecx, %esi // set aside sign of b
+
+ movl 12(%esp), %edx // high word of b
+ movl 8(%esp), %eax // low word of b
+ movl %edx, %ecx
+ sarl $31, %ecx // (a < 0) ? -1 : 0
+ xorl %ecx, %eax
+ xorl %ecx, %edx // EDX:EAX = (a < 0) ? not(a) : a
+ subl %ecx, %eax
+ sbbl %ecx, %edx // EDX:EAX = abs(a)
+ movl %edx, 12(%esp)
+ movl %eax, 8(%esp) // store abs(a) back to stack
+ xorl %ecx, %esi // sign of result = (sign of a) ^ (sign of b)
+
+ pushl %ebx
+ movl 24(%esp), %ebx // Find the index i of the leading bit in b.
+ bsrl %ebx, %ecx // If the high word of b is zero, jump to
+ jz 9f // the code to handle that special case [9].
+
+ /* High word of b is known to be non-zero on this branch */
+
+ movl 20(%esp), %eax // Construct bhi, containing bits [1+i:32+i] of b
+
+ shrl %cl, %eax // Practically, this means that bhi is given by:
+ shrl %eax //
+ notl %ecx // bhi = (high word of b) << (31 - i) |
+ shll %cl, %ebx // (low word of b) >> (1 + i)
+ orl %eax, %ebx //
+ movl 16(%esp), %edx // Load the high and low words of a, and jump
+ movl 12(%esp), %eax // to [1] if the high word is larger than bhi
+ cmpl %ebx, %edx // to avoid overflowing the upcoming divide.
+ jae 1f
+
+ /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ divl %ebx // eax <-- qs, edx <-- r such that ahi:alo = bs*qs + r
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ shrl %cl, %eax // q = qs >> (1 + i)
+ movl %eax, %edi
+ mull 24(%esp) // q*blo
+ movl 16(%esp), %ebx
+ movl 20(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 28(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+ sbbl $0, %edi // decrement q if remainder is negative
+ xorl %edx, %edx
+ movl %edi, %eax
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %edi // Restore callee-save registers
+ popl %ebx
+ popl %esi
+ retl // Return
+
+
+1: /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ subl %ebx, %edx // subtract bhi from ahi so that divide will not
+ divl %ebx // overflow, and find q and r such that
+ //
+ // ahi:alo = (1:q)*bhi + r
+ //
+ // Note that q is a number in (31-i).(1+i)
+ // fix point.
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ orl $0x80000000, %eax
+ shrl %cl, %eax // q = (1:qs) >> (1 + i)
+ movl %eax, %edi
+ mull 24(%esp) // q*blo
+ movl 16(%esp), %ebx
+ movl 20(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 28(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+ sbbl $0, %edi // decrement q if remainder is negative
+ xorl %edx, %edx
+ movl %edi, %eax
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %edi // Restore callee-save registers
+ popl %ebx
+ popl %esi
+ retl // Return
+
+
+9: /* High word of b is zero on this branch */
+
+ movl 16(%esp), %eax // Find qhi and rhi such that
+ movl 20(%esp), %ecx //
+ xorl %edx, %edx // ahi = qhi*b + rhi with 0 ≤ rhi < b
+ divl %ecx //
+ movl %eax, %ebx //
+ movl 12(%esp), %eax // Find qlo such that
+ divl %ecx //
+ movl %ebx, %edx // rhi:alo = qlo*b + rlo with 0 ≤ rlo < b
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %ebx // Restore callee-save registers
+ popl %esi
+ retl // Return
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatdidf.S b/contrib/compiler-rt/lib/i386/floatdidf.S
new file mode 100644
index 0000000..3a526ea
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatdidf.S
@@ -0,0 +1,35 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// double __floatundidf(du_int a);
+
+#ifdef __i386__
+
+#ifndef __ELF__
+.const
+#endif
+.align 4
+twop52: .quad 0x4330000000000000
+twop32: .quad 0x41f0000000000000
+
+#define REL_ADDR(_a) (_a)-0b(%eax)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatdidf)
+ cvtsi2sd 8(%esp), %xmm1
+ movss 4(%esp), %xmm0 // low 32 bits of a
+ calll 0f
+0: popl %eax
+ mulsd REL_ADDR(twop32), %xmm1 // a_hi as a double (without rounding)
+ movsd REL_ADDR(twop52), %xmm2 // 0x1.0p52
+ subsd %xmm2, %xmm1 // a_hi - 0x1p52 (no rounding occurs)
+ orpd %xmm2, %xmm0 // 0x1p52 + a_lo (no rounding occurs)
+ addsd %xmm1, %xmm0 // a_hi + a_lo (round happens here)
+ movsd %xmm0, 4(%esp)
+ fldl 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatdisf.S b/contrib/compiler-rt/lib/i386/floatdisf.S
new file mode 100644
index 0000000..741e4a6
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatdisf.S
@@ -0,0 +1,31 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// float __floatdisf(di_int a);
+
+// This routine has some extra memory traffic, loading the 64-bit input via two
+// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
+// store. This is to avoid a write-small, read-large stall.
+// However, if callers of this routine can be safely assumed to store the argument
+// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
+// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatdisf)
+#ifndef TRUST_CALLERS_USE_64_BIT_STORES
+ movd 4(%esp), %xmm0
+ movd 8(%esp), %xmm1
+ punpckldq %xmm1, %xmm0
+ movq %xmm0, 4(%esp)
+#endif
+ fildll 4(%esp)
+ fstps 4(%esp)
+ flds 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatdixf.S b/contrib/compiler-rt/lib/i386/floatdixf.S
new file mode 100644
index 0000000..f0271ab
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatdixf.S
@@ -0,0 +1,29 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// float __floatdixf(di_int a);
+
+#ifdef __i386__
+
+// This routine has some extra memory traffic, loading the 64-bit input via two
+// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
+// store. This is to avoid a write-small, read-large stall.
+// However, if callers of this routine can be safely assumed to store the argument
+// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
+// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatdixf)
+#ifndef TRUST_CALLERS_USE_64_BIT_STORES
+ movd 4(%esp), %xmm0
+ movd 8(%esp), %xmm1
+ punpckldq %xmm1, %xmm0
+ movq %xmm0, 4(%esp)
+#endif
+ fildll 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatundidf.S b/contrib/compiler-rt/lib/i386/floatundidf.S
new file mode 100644
index 0000000..7186a35
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatundidf.S
@@ -0,0 +1,46 @@
+//===-- floatundidf.S - Implement __floatundidf for i386 ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements __floatundidf for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+// double __floatundidf(du_int a);
+
+#ifdef __i386__
+
+#ifndef __ELF__
+.const
+#endif
+.align 4
+twop52: .quad 0x4330000000000000
+twop84_plus_twop52:
+ .quad 0x4530000000100000
+twop84: .quad 0x4530000000000000
+
+#define REL_ADDR(_a) (_a)-0b(%eax)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundidf)
+ movss 8(%esp), %xmm1 // high 32 bits of a
+ movss 4(%esp), %xmm0 // low 32 bits of a
+ calll 0f
+0: popl %eax
+ orpd REL_ADDR(twop84), %xmm1 // 0x1p84 + a_hi (no rounding occurs)
+ subsd REL_ADDR(twop84_plus_twop52), %xmm1 // a_hi - 0x1p52 (no rounding occurs)
+ orpd REL_ADDR(twop52), %xmm0 // 0x1p52 + a_lo (no rounding occurs)
+ addsd %xmm1, %xmm0 // a_hi + a_lo (round happens here)
+ movsd %xmm0, 4(%esp)
+ fldl 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatundisf.S b/contrib/compiler-rt/lib/i386/floatundisf.S
new file mode 100644
index 0000000..070820c
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatundisf.S
@@ -0,0 +1,99 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// float __floatundisf(du_int a);
+
+// Note that there is a hardware instruction, fildll, that does most of what
+// this function needs to do. However, because of our ia32 ABI, it will take
+// a write-small read-large stall, so the software implementation here is
+// actually several cycles faster.
+
+// This is a branch-free implementation. A branchy implementation might be
+// faster for the common case if you know something a priori about the input
+// distribution.
+
+/* branch-free x87 implementation - one cycle slower than without x87.
+
+#ifdef __i386__
+
+.const
+.align 3
+
+ .quad 0x43f0000000000000
+twop64: .quad 0x0000000000000000
+
+#define TWOp64 twop64-0b(%ecx,%eax,8)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundisf)
+ movl 8(%esp), %eax
+ movd 8(%esp), %xmm1
+ movd 4(%esp), %xmm0
+ punpckldq %xmm1, %xmm0
+ calll 0f
+0: popl %ecx
+ sarl $31, %eax
+ movq %xmm0, 4(%esp)
+ fildll 4(%esp)
+ faddl TWOp64
+ fstps 4(%esp)
+ flds 4(%esp)
+ ret
+
+#endif // __i386__
+
+*/
+
+/* branch-free, x87-free implementation - faster at the expense of code size */
+
+#ifdef __i386__
+
+#ifndef __ELF__
+.const
+.align 3
+#else
+.align 8
+#endif
+twop52: .quad 0x4330000000000000
+ .quad 0x0000000000000fff
+sticky: .quad 0x0000000000000000
+ .long 0x00000012
+twelve: .long 0x00000000
+
+#define TWOp52 twop52-0b(%ecx)
+#define STICKY sticky-0b(%ecx,%eax,8)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundisf)
+ movl 8(%esp), %eax
+ movd 8(%esp), %xmm1
+ movd 4(%esp), %xmm0
+ punpckldq %xmm1, %xmm0
+
+ calll 0f
+0: popl %ecx
+ shrl %eax // high 31 bits of input as sint32
+ addl $0x7ff80000, %eax
+ sarl $31, %eax // (big input) ? -1 : 0
+ movsd STICKY, %xmm1 // (big input) ? 0xfff : 0
+ movl $12, %edx
+ andl %eax, %edx // (big input) ? 12 : 0
+ movd %edx, %xmm3
+ andpd %xmm0, %xmm1 // (big input) ? input & 0xfff : 0
+ movsd TWOp52, %xmm2 // 0x1.0p52
+ psrlq %xmm3, %xmm0 // (big input) ? input >> 12 : input
+ orpd %xmm2, %xmm1 // 0x1.0p52 + ((big input) ? input & 0xfff : input)
+ orpd %xmm1, %xmm0 // 0x1.0p52 + ((big input) ? (input >> 12 | input & 0xfff) : input)
+ subsd %xmm2, %xmm0 // (double)((big input) ? (input >> 12 | input & 0xfff) : input)
+ cvtsd2ss %xmm0, %xmm0 // (float)((big input) ? (input >> 12 | input & 0xfff) : input)
+ pslld $23, %xmm3
+ paddd %xmm3, %xmm0 // (float)input
+ movd %xmm0, 4(%esp)
+ flds 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/floatundixf.S b/contrib/compiler-rt/lib/i386/floatundixf.S
new file mode 100644
index 0000000..2cf6d5c
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/floatundixf.S
@@ -0,0 +1,37 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// long double __floatundixf(du_int a);16
+
+#ifdef __i386__
+
+#ifndef __ELF__
+.const
+#endif
+.align 4
+twop52: .quad 0x4330000000000000
+twop84_plus_twop52_neg:
+ .quad 0xc530000000100000
+twop84: .quad 0x4530000000000000
+
+#define REL_ADDR(_a) (_a)-0b(%eax)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundixf)
+ calll 0f
+0: popl %eax
+ movss 8(%esp), %xmm0 // hi 32 bits of input
+ movss 4(%esp), %xmm1 // lo 32 bits of input
+ orpd REL_ADDR(twop84), %xmm0 // 2^84 + hi (as a double)
+ orpd REL_ADDR(twop52), %xmm1 // 2^52 + lo (as a double)
+ addsd REL_ADDR(twop84_plus_twop52_neg), %xmm0 // hi - 2^52 (no rounding occurs)
+ movsd %xmm1, 4(%esp)
+ fldl 4(%esp)
+ movsd %xmm0, 4(%esp)
+ faddl 4(%esp)
+ ret
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/lshrdi3.S b/contrib/compiler-rt/lib/i386/lshrdi3.S
new file mode 100644
index 0000000..74937d2
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/lshrdi3.S
@@ -0,0 +1,57 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __lshrdi3(di_int input, int count);
+
+// This routine has some extra memory traffic, loading the 64-bit input via two
+// 32-bit loads, then immediately storing it back to the stack via a single 64-bit
+// store. This is to avoid a write-small, read-large stall.
+// However, if callers of this routine can be safely assumed to store the argument
+// via a 64-bt store, this is unnecessary memory traffic, and should be avoided.
+// It can be turned off by defining the TRUST_CALLERS_USE_64_BIT_STORES macro.
+
+#ifdef __i386__
+#ifdef __SSE2__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__lshrdi3)
+ movd 12(%esp), %xmm2 // Load count
+#ifndef TRUST_CALLERS_USE_64_BIT_STORES
+ movd 4(%esp), %xmm0
+ movd 8(%esp), %xmm1
+ punpckldq %xmm1, %xmm0 // Load input
+#else
+ movq 4(%esp), %xmm0 // Load input
+#endif
+ psrlq %xmm2, %xmm0 // shift input by count
+ movd %xmm0, %eax
+ psrlq $32, %xmm0
+ movd %xmm0, %edx
+ ret
+
+#else // Use GPRs instead of SSE2 instructions, if they aren't available.
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__lshrdi3)
+ movl 12(%esp), %ecx // Load count
+ movl 8(%esp), %edx // Load high
+ movl 4(%esp), %eax // Load low
+
+ testl $0x20, %ecx // If count >= 32
+ jnz 1f // goto 1
+
+ shrdl %cl, %edx, %eax // right shift low by count
+ shrl %cl, %edx // right shift high by count
+ ret
+
+1: movl %edx, %eax // Move high to low
+ xorl %edx, %edx // clear high
+ shrl %cl, %eax // shift low by count - 32
+ ret
+
+#endif // __SSE2__
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/moddi3.S b/contrib/compiler-rt/lib/i386/moddi3.S
new file mode 100644
index 0000000..85f5b38
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/moddi3.S
@@ -0,0 +1,166 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __moddi3(di_int a, di_int b);
+
+// result = remainder of a / b.
+// both inputs and the output are 64-bit signed integers.
+// This will do whatever the underlying hardware is set to do on division by zero.
+// No other exceptions are generated, as the divide cannot overflow.
+//
+// This is targeted at 32-bit x86 *only*, as this can be done directly in hardware
+// on x86_64. The performance goal is ~40 cycles per divide, which is faster than
+// currently possible via simulation of integer divides on the x87 unit.
+//
+
+// Stephen Canon, December 2008
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__moddi3)
+
+/* This is currently implemented by wrapping the unsigned modulus up in an absolute
+ value. This could certainly be improved upon. */
+
+ pushl %esi
+ movl 20(%esp), %edx // high word of b
+ movl 16(%esp), %eax // low word of b
+ movl %edx, %ecx
+ sarl $31, %ecx // (b < 0) ? -1 : 0
+ xorl %ecx, %eax
+ xorl %ecx, %edx // EDX:EAX = (b < 0) ? not(b) : b
+ subl %ecx, %eax
+ sbbl %ecx, %edx // EDX:EAX = abs(b)
+ movl %edx, 20(%esp)
+ movl %eax, 16(%esp) // store abs(b) back to stack
+
+ movl 12(%esp), %edx // high word of b
+ movl 8(%esp), %eax // low word of b
+ movl %edx, %ecx
+ sarl $31, %ecx // (a < 0) ? -1 : 0
+ xorl %ecx, %eax
+ xorl %ecx, %edx // EDX:EAX = (a < 0) ? not(a) : a
+ subl %ecx, %eax
+ sbbl %ecx, %edx // EDX:EAX = abs(a)
+ movl %edx, 12(%esp)
+ movl %eax, 8(%esp) // store abs(a) back to stack
+ movl %ecx, %esi // set aside sign of a
+
+ pushl %ebx
+ movl 24(%esp), %ebx // Find the index i of the leading bit in b.
+ bsrl %ebx, %ecx // If the high word of b is zero, jump to
+ jz 9f // the code to handle that special case [9].
+
+ /* High word of b is known to be non-zero on this branch */
+
+ movl 20(%esp), %eax // Construct bhi, containing bits [1+i:32+i] of b
+
+ shrl %cl, %eax // Practically, this means that bhi is given by:
+ shrl %eax //
+ notl %ecx // bhi = (high word of b) << (31 - i) |
+ shll %cl, %ebx // (low word of b) >> (1 + i)
+ orl %eax, %ebx //
+ movl 16(%esp), %edx // Load the high and low words of a, and jump
+ movl 12(%esp), %eax // to [2] if the high word is larger than bhi
+ cmpl %ebx, %edx // to avoid overflowing the upcoming divide.
+ jae 2f
+
+ /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ divl %ebx // eax <-- qs, edx <-- r such that ahi:alo = bs*qs + r
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ shrl %cl, %eax // q = qs >> (1 + i)
+ movl %eax, %edi
+ mull 24(%esp) // q*blo
+ movl 16(%esp), %ebx
+ movl 20(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 28(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+
+ jnc 1f // if positive, this is the result.
+ addl 24(%esp), %ebx // otherwise
+ adcl 28(%esp), %ecx // ECX:EBX = a - (q-1)*b = result
+1: movl %ebx, %eax
+ movl %ecx, %edx
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %edi // Restore callee-save registers
+ popl %ebx
+ popl %esi
+ retl // Return
+
+2: /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ subl %ebx, %edx // subtract bhi from ahi so that divide will not
+ divl %ebx // overflow, and find q and r such that
+ //
+ // ahi:alo = (1:q)*bhi + r
+ //
+ // Note that q is a number in (31-i).(1+i)
+ // fix point.
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ orl $0x80000000, %eax
+ shrl %cl, %eax // q = (1:qs) >> (1 + i)
+ movl %eax, %edi
+ mull 24(%esp) // q*blo
+ movl 16(%esp), %ebx
+ movl 20(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 28(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+
+ jnc 3f // if positive, this is the result.
+ addl 24(%esp), %ebx // otherwise
+ adcl 28(%esp), %ecx // ECX:EBX = a - (q-1)*b = result
+3: movl %ebx, %eax
+ movl %ecx, %edx
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %edi // Restore callee-save registers
+ popl %ebx
+ popl %esi
+ retl // Return
+
+9: /* High word of b is zero on this branch */
+
+ movl 16(%esp), %eax // Find qhi and rhi such that
+ movl 20(%esp), %ecx //
+ xorl %edx, %edx // ahi = qhi*b + rhi with 0 ≤ rhi < b
+ divl %ecx //
+ movl %eax, %ebx //
+ movl 12(%esp), %eax // Find rlo such that
+ divl %ecx //
+ movl %edx, %eax // rhi:alo = qlo*b + rlo with 0 ≤ rlo < b
+ popl %ebx //
+ xorl %edx, %edx // and return 0:rlo
+
+ addl %esi, %eax // Restore correct sign to result
+ adcl %esi, %edx
+ xorl %esi, %eax
+ xorl %esi, %edx
+ popl %esi
+ retl // Return
+
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/muldi3.S b/contrib/compiler-rt/lib/i386/muldi3.S
new file mode 100644
index 0000000..5f99f6a
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/muldi3.S
@@ -0,0 +1,29 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// di_int __muldi3(di_int a, di_int b);
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__muldi3)
+ pushl %ebx
+ movl 16(%esp), %eax // b.lo
+ movl 12(%esp), %ecx // a.hi
+ imull %eax, %ecx // b.lo * a.hi
+
+ movl 8(%esp), %edx // a.lo
+ movl 20(%esp), %ebx // b.hi
+ imull %edx, %ebx // a.lo * b.hi
+
+ mull %edx // EDX:EAX = a.lo * b.lo
+ addl %ecx, %ebx // EBX = (a.lo*b.hi + a.hi*b.lo)
+ addl %ebx, %edx
+
+ popl %ebx
+ retl
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/udivdi3.S b/contrib/compiler-rt/lib/i386/udivdi3.S
new file mode 100644
index 0000000..77936f8
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/udivdi3.S
@@ -0,0 +1,114 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// du_int __udivdi3(du_int a, du_int b);
+
+// result = a / b.
+// both inputs and the output are 64-bit unsigned integers.
+// This will do whatever the underlying hardware is set to do on division by zero.
+// No other exceptions are generated, as the divide cannot overflow.
+//
+// This is targeted at 32-bit x86 *only*, as this can be done directly in hardware
+// on x86_64. The performance goal is ~40 cycles per divide, which is faster than
+// currently possible via simulation of integer divides on the x87 unit.
+//
+// Stephen Canon, December 2008
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__udivdi3)
+
+ pushl %ebx
+ movl 20(%esp), %ebx // Find the index i of the leading bit in b.
+ bsrl %ebx, %ecx // If the high word of b is zero, jump to
+ jz 9f // the code to handle that special case [9].
+
+ /* High word of b is known to be non-zero on this branch */
+
+ movl 16(%esp), %eax // Construct bhi, containing bits [1+i:32+i] of b
+
+ shrl %cl, %eax // Practically, this means that bhi is given by:
+ shrl %eax //
+ notl %ecx // bhi = (high word of b) << (31 - i) |
+ shll %cl, %ebx // (low word of b) >> (1 + i)
+ orl %eax, %ebx //
+ movl 12(%esp), %edx // Load the high and low words of a, and jump
+ movl 8(%esp), %eax // to [1] if the high word is larger than bhi
+ cmpl %ebx, %edx // to avoid overflowing the upcoming divide.
+ jae 1f
+
+ /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ divl %ebx // eax <-- qs, edx <-- r such that ahi:alo = bs*qs + r
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ shrl %cl, %eax // q = qs >> (1 + i)
+ movl %eax, %edi
+ mull 20(%esp) // q*blo
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 24(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+ sbbl $0, %edi // decrement q if remainder is negative
+ xorl %edx, %edx
+ movl %edi, %eax
+ popl %edi
+ popl %ebx
+ retl
+
+
+1: /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ subl %ebx, %edx // subtract bhi from ahi so that divide will not
+ divl %ebx // overflow, and find q and r such that
+ //
+ // ahi:alo = (1:q)*bhi + r
+ //
+ // Note that q is a number in (31-i).(1+i)
+ // fix point.
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ orl $0x80000000, %eax
+ shrl %cl, %eax // q = (1:qs) >> (1 + i)
+ movl %eax, %edi
+ mull 20(%esp) // q*blo
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 24(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+ sbbl $0, %edi // decrement q if remainder is negative
+ xorl %edx, %edx
+ movl %edi, %eax
+ popl %edi
+ popl %ebx
+ retl
+
+
+9: /* High word of b is zero on this branch */
+
+ movl 12(%esp), %eax // Find qhi and rhi such that
+ movl 16(%esp), %ecx //
+ xorl %edx, %edx // ahi = qhi*b + rhi with 0 ≤ rhi < b
+ divl %ecx //
+ movl %eax, %ebx //
+ movl 8(%esp), %eax // Find qlo such that
+ divl %ecx //
+ movl %ebx, %edx // rhi:alo = qlo*b + rlo with 0 ≤ rlo < b
+ popl %ebx //
+ retl // and return qhi:qlo
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/i386/umoddi3.S b/contrib/compiler-rt/lib/i386/umoddi3.S
new file mode 100644
index 0000000..3cf8aeb
--- /dev/null
+++ b/contrib/compiler-rt/lib/i386/umoddi3.S
@@ -0,0 +1,125 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// du_int __umoddi3(du_int a, du_int b);
+
+// result = remainder of a / b.
+// both inputs and the output are 64-bit unsigned integers.
+// This will do whatever the underlying hardware is set to do on division by zero.
+// No other exceptions are generated, as the divide cannot overflow.
+//
+// This is targeted at 32-bit x86 *only*, as this can be done directly in hardware
+// on x86_64. The performance goal is ~40 cycles per divide, which is faster than
+// currently possible via simulation of integer divides on the x87 unit.
+//
+
+// Stephen Canon, December 2008
+
+#ifdef __i386__
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__umoddi3)
+
+ pushl %ebx
+ movl 20(%esp), %ebx // Find the index i of the leading bit in b.
+ bsrl %ebx, %ecx // If the high word of b is zero, jump to
+ jz 9f // the code to handle that special case [9].
+
+ /* High word of b is known to be non-zero on this branch */
+
+ movl 16(%esp), %eax // Construct bhi, containing bits [1+i:32+i] of b
+
+ shrl %cl, %eax // Practically, this means that bhi is given by:
+ shrl %eax //
+ notl %ecx // bhi = (high word of b) << (31 - i) |
+ shll %cl, %ebx // (low word of b) >> (1 + i)
+ orl %eax, %ebx //
+ movl 12(%esp), %edx // Load the high and low words of a, and jump
+ movl 8(%esp), %eax // to [2] if the high word is larger than bhi
+ cmpl %ebx, %edx // to avoid overflowing the upcoming divide.
+ jae 2f
+
+ /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ divl %ebx // eax <-- qs, edx <-- r such that ahi:alo = bs*qs + r
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ shrl %cl, %eax // q = qs >> (1 + i)
+ movl %eax, %edi
+ mull 20(%esp) // q*blo
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 24(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+
+ jnc 1f // if positive, this is the result.
+ addl 20(%esp), %ebx // otherwise
+ adcl 24(%esp), %ecx // ECX:EBX = a - (q-1)*b = result
+1: movl %ebx, %eax
+ movl %ecx, %edx
+
+ popl %edi
+ popl %ebx
+ retl
+
+
+2: /* High word of a is greater than or equal to (b >> (1 + i)) on this branch */
+
+ subl %ebx, %edx // subtract bhi from ahi so that divide will not
+ divl %ebx // overflow, and find q and r such that
+ //
+ // ahi:alo = (1:q)*bhi + r
+ //
+ // Note that q is a number in (31-i).(1+i)
+ // fix point.
+
+ pushl %edi
+ notl %ecx
+ shrl %eax
+ orl $0x80000000, %eax
+ shrl %cl, %eax // q = (1:qs) >> (1 + i)
+ movl %eax, %edi
+ mull 20(%esp) // q*blo
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ecx // ECX:EBX = a
+ subl %eax, %ebx
+ sbbl %edx, %ecx // ECX:EBX = a - q*blo
+ movl 24(%esp), %eax
+ imull %edi, %eax // q*bhi
+ subl %eax, %ecx // ECX:EBX = a - q*b
+
+ jnc 3f // if positive, this is the result.
+ addl 20(%esp), %ebx // otherwise
+ adcl 24(%esp), %ecx // ECX:EBX = a - (q-1)*b = result
+3: movl %ebx, %eax
+ movl %ecx, %edx
+
+ popl %edi
+ popl %ebx
+ retl
+
+
+
+9: /* High word of b is zero on this branch */
+
+ movl 12(%esp), %eax // Find qhi and rhi such that
+ movl 16(%esp), %ecx //
+ xorl %edx, %edx // ahi = qhi*b + rhi with 0 ≤ rhi < b
+ divl %ecx //
+ movl %eax, %ebx //
+ movl 8(%esp), %eax // Find rlo such that
+ divl %ecx //
+ movl %edx, %eax // rhi:alo = qlo*b + rlo with 0 ≤ rlo < b
+ popl %ebx //
+ xorl %edx, %edx // and return 0:rlo
+ retl //
+
+#endif // __i386__
diff --git a/contrib/compiler-rt/lib/int_lib.h b/contrib/compiler-rt/lib/int_lib.h
new file mode 100644
index 0000000..912a12f
--- /dev/null
+++ b/contrib/compiler-rt/lib/int_lib.h
@@ -0,0 +1,155 @@
+/* ===-- int_lib.h - configuration header for compiler-rt -----------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file is a configuration header for compiler-rt.
+ * This file is not part of the interface of this library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#ifndef INT_LIB_H
+#define INT_LIB_H
+
+/* Assumption: signed integral is 2's complement */
+/* Assumption: right shift of signed negative is arithmetic shift */
+
+#include <limits.h>
+#include "endianness.h"
+#include <math.h>
+
+/* If compiling for kernel use, call panic() instead of abort(). */
+#ifdef KERNEL_USE
+extern void panic (const char *, ...);
+#define compilerrt_abort() \
+ panic("%s:%d: abort in %s", __FILE__, __LINE__, __FUNCTION__)
+#else
+#define compilerrt_abort() abort()
+#endif
+
+#if !defined(INFINITY) && defined(HUGE_VAL)
+#define INFINITY HUGE_VAL
+#endif /* INFINITY */
+
+typedef int si_int;
+typedef unsigned su_int;
+
+typedef long long di_int;
+typedef unsigned long long du_int;
+
+typedef union
+{
+ di_int all;
+ struct
+ {
+#if _YUGA_LITTLE_ENDIAN
+ su_int low;
+ si_int high;
+#else
+ si_int high;
+ su_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+ }s;
+} dwords;
+
+typedef union
+{
+ du_int all;
+ struct
+ {
+#if _YUGA_LITTLE_ENDIAN
+ su_int low;
+ su_int high;
+#else
+ su_int high;
+ su_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+ }s;
+} udwords;
+
+#if __x86_64
+
+typedef int ti_int __attribute__ ((mode (TI)));
+typedef unsigned tu_int __attribute__ ((mode (TI)));
+
+typedef union
+{
+ ti_int all;
+ struct
+ {
+#if _YUGA_LITTLE_ENDIAN
+ du_int low;
+ di_int high;
+#else
+ di_int high;
+ du_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+ }s;
+} twords;
+
+typedef union
+{
+ tu_int all;
+ struct
+ {
+#if _YUGA_LITTLE_ENDIAN
+ du_int low;
+ du_int high;
+#else
+ du_int high;
+ du_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+ }s;
+} utwords;
+
+static inline ti_int make_ti(di_int h, di_int l) {
+ twords r;
+ r.s.high = h;
+ r.s.low = l;
+ return r.all;
+}
+
+static inline tu_int make_tu(du_int h, du_int l) {
+ utwords r;
+ r.s.high = h;
+ r.s.low = l;
+ return r.all;
+}
+
+#endif /* __x86_64 */
+
+typedef union
+{
+ su_int u;
+ float f;
+} float_bits;
+
+typedef union
+{
+ udwords u;
+ double f;
+} double_bits;
+
+typedef struct
+{
+#if _YUGA_LITTLE_ENDIAN
+ udwords low;
+ udwords high;
+#else
+ udwords high;
+ udwords low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+} uqwords;
+
+typedef union
+{
+ uqwords u;
+ long double f;
+} long_double_bits;
+
+#endif /* INT_LIB_H */
diff --git a/contrib/compiler-rt/lib/lshrdi3.c b/contrib/compiler-rt/lib/lshrdi3.c
new file mode 100644
index 0000000..57484ee
--- /dev/null
+++ b/contrib/compiler-rt/lib/lshrdi3.c
@@ -0,0 +1,41 @@
+/* ===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __lshrdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: logical a >> b */
+
+/* Precondition: 0 <= b < bits_in_dword */
+
+di_int
+__lshrdi3(di_int a, si_int b)
+{
+ const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
+ udwords input;
+ udwords result;
+ input.all = a;
+ if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
+ {
+ result.s.high = 0;
+ result.s.low = input.s.high >> (b - bits_in_word);
+ }
+ else /* 0 <= b < bits_in_word */
+ {
+ if (b == 0)
+ return a;
+ result.s.high = input.s.high >> b;
+ result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b);
+ }
+ return result.all;
+}
diff --git a/contrib/compiler-rt/lib/lshrti3.c b/contrib/compiler-rt/lib/lshrti3.c
new file mode 100644
index 0000000..3272c9c
--- /dev/null
+++ b/contrib/compiler-rt/lib/lshrti3.c
@@ -0,0 +1,45 @@
+/* ===-- lshrti3.c - Implement __lshrti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __lshrti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: logical a >> b */
+
+/* Precondition: 0 <= b < bits_in_tword */
+
+ti_int
+__lshrti3(ti_int a, si_int b)
+{
+ const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
+ utwords input;
+ utwords result;
+ input.all = a;
+ if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
+ {
+ result.s.high = 0;
+ result.s.low = input.s.high >> (b - bits_in_dword);
+ }
+ else /* 0 <= b < bits_in_dword */
+ {
+ if (b == 0)
+ return a;
+ result.s.high = input.s.high >> b;
+ result.s.low = (input.s.high << (bits_in_dword - b)) | (input.s.low >> b);
+ }
+ return result.all;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/moddi3.c b/contrib/compiler-rt/lib/moddi3.c
new file mode 100644
index 0000000..4533555
--- /dev/null
+++ b/contrib/compiler-rt/lib/moddi3.c
@@ -0,0 +1,32 @@
+/*===-- moddi3.c - Implement __moddi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __moddi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
+
+/* Returns: a % b */
+
+di_int
+__moddi3(di_int a, di_int b)
+{
+ const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
+ di_int s = b >> bits_in_dword_m1; /* s = b < 0 ? -1 : 0 */
+ b = (b ^ s) - s; /* negate if s == -1 */
+ s = a >> bits_in_dword_m1; /* s = a < 0 ? -1 : 0 */
+ a = (a ^ s) - s; /* negate if s == -1 */
+ di_int r;
+ __udivmoddi4(a, b, (du_int*)&r);
+ return (r ^ s) - s; /* negate if s == -1 */
+}
diff --git a/contrib/compiler-rt/lib/modsi3.c b/contrib/compiler-rt/lib/modsi3.c
new file mode 100644
index 0000000..c9214a2
--- /dev/null
+++ b/contrib/compiler-rt/lib/modsi3.c
@@ -0,0 +1,23 @@
+/* ===-- modsi3.c - Implement __modsi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __modsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a % b */
+
+si_int
+__modsi3(si_int a, si_int b)
+{
+ return a - (a / b) * b;
+}
diff --git a/contrib/compiler-rt/lib/modti3.c b/contrib/compiler-rt/lib/modti3.c
new file mode 100644
index 0000000..75d688e
--- /dev/null
+++ b/contrib/compiler-rt/lib/modti3.c
@@ -0,0 +1,36 @@
+/* ===-- modti3.c - Implement __modti3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __modti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
+
+/*Returns: a % b */
+
+ti_int
+__modti3(ti_int a, ti_int b)
+{
+ const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
+ ti_int s = b >> bits_in_tword_m1; /* s = b < 0 ? -1 : 0 */
+ b = (b ^ s) - s; /* negate if s == -1 */
+ s = a >> bits_in_tword_m1; /* s = a < 0 ? -1 : 0 */
+ a = (a ^ s) - s; /* negate if s == -1 */
+ ti_int r;
+ __udivmodti4(a, b, (tu_int*)&r);
+ return (r ^ s) - s; /* negate if s == -1 */
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/muldc3.c b/contrib/compiler-rt/lib/muldc3.c
new file mode 100644
index 0000000..c048d84
--- /dev/null
+++ b/contrib/compiler-rt/lib/muldc3.c
@@ -0,0 +1,74 @@
+/* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __muldc3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the product of a + ib and c + id */
+
+double _Complex
+__muldc3(double __a, double __b, double __c, double __d)
+{
+ double __ac = __a * __c;
+ double __bd = __b * __d;
+ double __ad = __a * __d;
+ double __bc = __b * __c;
+ double _Complex z;
+ __real__ z = __ac - __bd;
+ __imag__ z = __ad + __bc;
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ int __recalc = 0;
+ if (isinf(__a) || isinf(__b))
+ {
+ __a = copysign(isinf(__a) ? 1 : 0, __a);
+ __b = copysign(isinf(__b) ? 1 : 0, __b);
+ if (isnan(__c))
+ __c = copysign(0, __c);
+ if (isnan(__d))
+ __d = copysign(0, __d);
+ __recalc = 1;
+ }
+ if (isinf(__c) || isinf(__d))
+ {
+ __c = copysign(isinf(__c) ? 1 : 0, __c);
+ __d = copysign(isinf(__d) ? 1 : 0, __d);
+ if (isnan(__a))
+ __a = copysign(0, __a);
+ if (isnan(__b))
+ __b = copysign(0, __b);
+ __recalc = 1;
+ }
+ if (!__recalc && (isinf(__ac) || isinf(__bd) ||
+ isinf(__ad) || isinf(__bc)))
+ {
+ if (isnan(__a))
+ __a = copysign(0, __a);
+ if (isnan(__b))
+ __b = copysign(0, __b);
+ if (isnan(__c))
+ __c = copysign(0, __c);
+ if (isnan(__d))
+ __d = copysign(0, __d);
+ __recalc = 1;
+ }
+ if (__recalc)
+ {
+ __real__ z = INFINITY * (__a * __c - __b * __d);
+ __imag__ z = INFINITY * (__a * __d + __b * __c);
+ }
+ }
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/muldf3.c b/contrib/compiler-rt/lib/muldf3.c
new file mode 100644
index 0000000..63a473e
--- /dev/null
+++ b/contrib/compiler-rt/lib/muldf3.c
@@ -0,0 +1,119 @@
+//===-- lib/muldf3.c - Double-precision multiplication ------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements double-precision soft-float multiplication
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __muldf3(fp_t a, fp_t b) {
+
+ const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
+ const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
+ const rep_t productSign = (toRep(a) ^ toRep(b)) & signBit;
+
+ rep_t aSignificand = toRep(a) & significandMask;
+ rep_t bSignificand = toRep(b) & significandMask;
+ int scale = 0;
+
+ // Detect if a or b is zero, denormal, infinity, or NaN.
+ if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
+
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+
+ // NaN * anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything * NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // infinity * non-zero = +/- infinity
+ if (bAbs) return fromRep(aAbs | productSign);
+ // infinity * zero = NaN
+ else return fromRep(qnanRep);
+ }
+
+ if (bAbs == infRep) {
+ // non-zero * infinity = +/- infinity
+ if (aAbs) return fromRep(bAbs | productSign);
+ // zero * infinity = NaN
+ else return fromRep(qnanRep);
+ }
+
+ // zero * anything = +/- zero
+ if (!aAbs) return fromRep(productSign);
+ // anything * zero = +/- zero
+ if (!bAbs) return fromRep(productSign);
+
+ // one or both of a or b is denormal, the other (if applicable) is a
+ // normal number. Renormalize one or both of a and b, and set scale to
+ // include the necessary exponent adjustment.
+ if (aAbs < implicitBit) scale += normalize(&aSignificand);
+ if (bAbs < implicitBit) scale += normalize(&bSignificand);
+ }
+
+ // Or in the implicit significand bit. (If we fell through from the
+ // denormal path it was already set by normalize( ), but setting it twice
+ // won't hurt anything.)
+ aSignificand |= implicitBit;
+ bSignificand |= implicitBit;
+
+ // Get the significand of a*b. Before multiplying the significands, shift
+ // one of them left to left-align it in the field. Thus, the product will
+ // have (exponentBits + 2) integral digits, all but two of which must be
+ // zero. Normalizing this result is just a conditional left-shift by one
+ // and bumping the exponent accordingly.
+ rep_t productHi, productLo;
+ wideMultiply(aSignificand, bSignificand << exponentBits,
+ &productHi, &productLo);
+
+ int productExponent = aExponent + bExponent - exponentBias + scale;
+
+ // Normalize the significand, adjust exponent if needed.
+ if (productHi & implicitBit) productExponent++;
+ else wideLeftShift(&productHi, &productLo, 1);
+
+ // If we have overflowed the type, return +/- infinity.
+ if (productExponent >= maxExponent) return fromRep(infRep | productSign);
+
+ if (productExponent <= 0) {
+ // Result is denormal before rounding
+ //
+ // If the result is so small that it just underflows to zero, return
+ // a zero of the appropriate sign. Mathematically there is no need to
+ // handle this case separately, but we make it a special case to
+ // simplify the shift logic.
+ const int shift = 1 - productExponent;
+ if (shift >= typeWidth) return fromRep(productSign);
+
+ // Otherwise, shift the significand of the result so that the round
+ // bit is the high bit of productLo.
+ wideRightShiftWithSticky(&productHi, &productLo, shift);
+ }
+
+ else {
+ // Result is normal before rounding; insert the exponent.
+ productHi &= significandMask;
+ productHi |= (rep_t)productExponent << significandBits;
+ }
+
+ // Insert the sign of the result:
+ productHi |= productSign;
+
+ // Final rounding. The final result may overflow to infinity, or underflow
+ // to zero, but those are the correct results in those cases. We use the
+ // default IEEE-754 round-to-nearest, ties-to-even rounding mode.
+ if (productLo > signBit) productHi++;
+ if (productLo == signBit) productHi += productHi & 1;
+ return fromRep(productHi);
+}
diff --git a/contrib/compiler-rt/lib/muldi3.c b/contrib/compiler-rt/lib/muldi3.c
new file mode 100644
index 0000000..38963b7
--- /dev/null
+++ b/contrib/compiler-rt/lib/muldi3.c
@@ -0,0 +1,54 @@
+/* ===-- muldi3.c - Implement __muldi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __muldi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a * b */
+
+static
+di_int
+__muldsi3(su_int a, su_int b)
+{
+ dwords r;
+ const int bits_in_word_2 = (int)(sizeof(si_int) * CHAR_BIT) / 2;
+ const su_int lower_mask = (su_int)~0 >> bits_in_word_2;
+ r.s.low = (a & lower_mask) * (b & lower_mask);
+ su_int t = r.s.low >> bits_in_word_2;
+ r.s.low &= lower_mask;
+ t += (a >> bits_in_word_2) * (b & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_word_2;
+ r.s.high = t >> bits_in_word_2;
+ t = r.s.low >> bits_in_word_2;
+ r.s.low &= lower_mask;
+ t += (b >> bits_in_word_2) * (a & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_word_2;
+ r.s.high += t >> bits_in_word_2;
+ r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2);
+ return r.all;
+}
+
+/* Returns: a * b */
+
+di_int
+__muldi3(di_int a, di_int b)
+{
+ dwords x;
+ x.all = a;
+ dwords y;
+ y.all = b;
+ dwords r;
+ r.all = __muldsi3(x.s.low, y.s.low);
+ r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+ return r.all;
+}
diff --git a/contrib/compiler-rt/lib/mulsc3.c b/contrib/compiler-rt/lib/mulsc3.c
new file mode 100644
index 0000000..c7b9f64
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulsc3.c
@@ -0,0 +1,74 @@
+/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __mulsc3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the product of a + ib and c + id */
+
+float _Complex
+__mulsc3(float __a, float __b, float __c, float __d)
+{
+ float __ac = __a * __c;
+ float __bd = __b * __d;
+ float __ad = __a * __d;
+ float __bc = __b * __c;
+ float _Complex z;
+ __real__ z = __ac - __bd;
+ __imag__ z = __ad + __bc;
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ int __recalc = 0;
+ if (isinf(__a) || isinf(__b))
+ {
+ __a = copysignf(isinf(__a) ? 1 : 0, __a);
+ __b = copysignf(isinf(__b) ? 1 : 0, __b);
+ if (isnan(__c))
+ __c = copysignf(0, __c);
+ if (isnan(__d))
+ __d = copysignf(0, __d);
+ __recalc = 1;
+ }
+ if (isinf(__c) || isinf(__d))
+ {
+ __c = copysignf(isinf(__c) ? 1 : 0, __c);
+ __d = copysignf(isinf(__d) ? 1 : 0, __d);
+ if (isnan(__a))
+ __a = copysignf(0, __a);
+ if (isnan(__b))
+ __b = copysignf(0, __b);
+ __recalc = 1;
+ }
+ if (!__recalc && (isinf(__ac) || isinf(__bd) ||
+ isinf(__ad) || isinf(__bc)))
+ {
+ if (isnan(__a))
+ __a = copysignf(0, __a);
+ if (isnan(__b))
+ __b = copysignf(0, __b);
+ if (isnan(__c))
+ __c = copysignf(0, __c);
+ if (isnan(__d))
+ __d = copysignf(0, __d);
+ __recalc = 1;
+ }
+ if (__recalc)
+ {
+ __real__ z = INFINITY * (__a * __c - __b * __d);
+ __imag__ z = INFINITY * (__a * __d + __b * __c);
+ }
+ }
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/mulsf3.c b/contrib/compiler-rt/lib/mulsf3.c
new file mode 100644
index 0000000..6bd2f9d
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulsf3.c
@@ -0,0 +1,109 @@
+//===-- lib/mulsf3.c - Single-precision multiplication ------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements single-precision soft-float multiplication
+// with the IEEE-754 default rounding (to nearest, ties to even).
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __mulsf3(fp_t a, fp_t b) {
+
+ const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
+ const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
+ const rep_t productSign = (toRep(a) ^ toRep(b)) & signBit;
+
+ rep_t aSignificand = toRep(a) & significandMask;
+ rep_t bSignificand = toRep(b) & significandMask;
+ int scale = 0;
+
+ // Detect if a or b is zero, denormal, infinity, or NaN.
+ if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
+
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+
+ // NaN * anything = qNaN
+ if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
+ // anything * NaN = qNaN
+ if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
+
+ if (aAbs == infRep) {
+ // infinity * non-zero = +/- infinity
+ if (bAbs) return fromRep(aAbs | productSign);
+ // infinity * zero = NaN
+ else return fromRep(qnanRep);
+ }
+
+ if (bAbs == infRep) {
+ // non-zero * infinity = +/- infinity
+ if (aAbs) return fromRep(bAbs | productSign);
+ // zero * infinity = NaN
+ else return fromRep(qnanRep);
+ }
+
+ // zero * anything = +/- zero
+ if (!aAbs) return fromRep(productSign);
+ // anything * zero = +/- zero
+ if (!bAbs) return fromRep(productSign);
+
+ // one or both of a or b is denormal, the other (if applicable) is a
+ // normal number. Renormalize one or both of a and b, and set scale to
+ // include the necessary exponent adjustment.
+ if (aAbs < implicitBit) scale += normalize(&aSignificand);
+ if (bAbs < implicitBit) scale += normalize(&bSignificand);
+ }
+
+ // Or in the implicit significand bit. (If we fell through from the
+ // denormal path it was already set by normalize( ), but setting it twice
+ // won't hurt anything.)
+ aSignificand |= implicitBit;
+ bSignificand |= implicitBit;
+
+ // Get the significand of a*b. Before multiplying the significands, shift
+ // one of them left to left-align it in the field. Thus, the product will
+ // have (exponentBits + 2) integral digits, all but two of which must be
+ // zero. Normalizing this result is just a conditional left-shift by one
+ // and bumping the exponent accordingly.
+ rep_t productHi, productLo;
+ wideMultiply(aSignificand, bSignificand << exponentBits,
+ &productHi, &productLo);
+
+ int productExponent = aExponent + bExponent - exponentBias + scale;
+
+ // Normalize the significand, adjust exponent if needed.
+ if (productHi & implicitBit) productExponent++;
+ else wideLeftShift(&productHi, &productLo, 1);
+
+ // If we have overflowed the type, return +/- infinity.
+ if (productExponent >= maxExponent) return fromRep(infRep | productSign);
+
+ if (productExponent <= 0) {
+ // Result is denormal before rounding, the exponent is zero and we
+ // need to shift the significand.
+ wideRightShiftWithSticky(&productHi, &productLo, 1 - productExponent);
+ }
+
+ else {
+ // Result is normal before rounding; insert the exponent.
+ productHi &= significandMask;
+ productHi |= (rep_t)productExponent << significandBits;
+ }
+
+ // Insert the sign of the result:
+ productHi |= productSign;
+
+ // Final rounding. The final result may overflow to infinity, or underflow
+ // to zero, but those are the correct results in those cases.
+ if (productLo > signBit) productHi++;
+ if (productLo == signBit) productHi += productHi & 1;
+ return fromRep(productHi);
+}
diff --git a/contrib/compiler-rt/lib/multi3.c b/contrib/compiler-rt/lib/multi3.c
new file mode 100644
index 0000000..13a3867
--- /dev/null
+++ b/contrib/compiler-rt/lib/multi3.c
@@ -0,0 +1,58 @@
+/* ===-- multi3.c - Implement __multi3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+
+ * This file implements __multi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: a * b */
+
+static
+ti_int
+__mulddi3(du_int a, du_int b)
+{
+ twords r;
+ const int bits_in_dword_2 = (int)(sizeof(di_int) * CHAR_BIT) / 2;
+ const du_int lower_mask = (du_int)~0 >> bits_in_dword_2;
+ r.s.low = (a & lower_mask) * (b & lower_mask);
+ du_int t = r.s.low >> bits_in_dword_2;
+ r.s.low &= lower_mask;
+ t += (a >> bits_in_dword_2) * (b & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_dword_2;
+ r.s.high = t >> bits_in_dword_2;
+ t = r.s.low >> bits_in_dword_2;
+ r.s.low &= lower_mask;
+ t += (b >> bits_in_dword_2) * (a & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_dword_2;
+ r.s.high += t >> bits_in_dword_2;
+ r.s.high += (a >> bits_in_dword_2) * (b >> bits_in_dword_2);
+ return r.all;
+}
+
+/* Returns: a * b */
+
+ti_int
+__multi3(ti_int a, ti_int b)
+{
+ twords x;
+ x.all = a;
+ twords y;
+ y.all = b;
+ twords r;
+ r.all = __mulddi3(x.s.low, y.s.low);
+ r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+ return r.all;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/mulvdi3.c b/contrib/compiler-rt/lib/mulvdi3.c
new file mode 100644
index 0000000..295ae18
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulvdi3.c
@@ -0,0 +1,57 @@
+/*===-- mulvdi3.c - Implement __mulvdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __mulvdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a * b */
+
+/* Effects: aborts if a * b overflows */
+
+di_int
+__mulvdi3(di_int a, di_int b)
+{
+ const int N = (int)(sizeof(di_int) * CHAR_BIT);
+ const di_int MIN = (di_int)1 << (N-1);
+ const di_int MAX = ~MIN;
+ if (a == MIN)
+ {
+ if (b == 0 || b == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ if (b == MIN)
+ {
+ if (a == 0 || a == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ di_int sa = a >> (N - 1);
+ di_int abs_a = (a ^ sa) - sa;
+ di_int sb = b >> (N - 1);
+ di_int abs_b = (b ^ sb) - sb;
+ if (abs_a < 2 || abs_b < 2)
+ return a * b;
+ if (sa == sb)
+ {
+ if (abs_a > MAX / abs_b)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (abs_a > MIN / -abs_b)
+ compilerrt_abort();
+ }
+ return a * b;
+}
diff --git a/contrib/compiler-rt/lib/mulvsi3.c b/contrib/compiler-rt/lib/mulvsi3.c
new file mode 100644
index 0000000..b4a509b
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulvsi3.c
@@ -0,0 +1,57 @@
+/* ===-- mulvsi3.c - Implement __mulvsi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __mulvsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a * b */
+
+/* Effects: aborts if a * b overflows */
+
+si_int
+__mulvsi3(si_int a, si_int b)
+{
+ const int N = (int)(sizeof(si_int) * CHAR_BIT);
+ const si_int MIN = (si_int)1 << (N-1);
+ const si_int MAX = ~MIN;
+ if (a == MIN)
+ {
+ if (b == 0 || b == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ if (b == MIN)
+ {
+ if (a == 0 || a == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ si_int sa = a >> (N - 1);
+ si_int abs_a = (a ^ sa) - sa;
+ si_int sb = b >> (N - 1);
+ si_int abs_b = (b ^ sb) - sb;
+ if (abs_a < 2 || abs_b < 2)
+ return a * b;
+ if (sa == sb)
+ {
+ if (abs_a > MAX / abs_b)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (abs_a > MIN / -abs_b)
+ compilerrt_abort();
+ }
+ return a * b;
+}
diff --git a/contrib/compiler-rt/lib/mulvti3.c b/contrib/compiler-rt/lib/mulvti3.c
new file mode 100644
index 0000000..778222e
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulvti3.c
@@ -0,0 +1,61 @@
+/* ===-- mulvti3.c - Implement __mulvti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __mulvti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a * b */
+
+/* Effects: aborts if a * b overflows */
+
+ti_int
+__mulvti3(ti_int a, ti_int b)
+{
+ const int N = (int)(sizeof(ti_int) * CHAR_BIT);
+ const ti_int MIN = (ti_int)1 << (N-1);
+ const ti_int MAX = ~MIN;
+ if (a == MIN)
+ {
+ if (b == 0 || b == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ if (b == MIN)
+ {
+ if (a == 0 || a == 1)
+ return a * b;
+ compilerrt_abort();
+ }
+ ti_int sa = a >> (N - 1);
+ ti_int abs_a = (a ^ sa) - sa;
+ ti_int sb = b >> (N - 1);
+ ti_int abs_b = (b ^ sb) - sb;
+ if (abs_a < 2 || abs_b < 2)
+ return a * b;
+ if (sa == sb)
+ {
+ if (abs_a > MAX / abs_b)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (abs_a > MIN / -abs_b)
+ compilerrt_abort();
+ }
+ return a * b;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/mulxc3.c b/contrib/compiler-rt/lib/mulxc3.c
new file mode 100644
index 0000000..94895f2
--- /dev/null
+++ b/contrib/compiler-rt/lib/mulxc3.c
@@ -0,0 +1,78 @@
+/* ===-- mulxc3.c - Implement __mulxc3 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __mulxc3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+#include <math.h>
+#include <complex.h>
+
+/* Returns: the product of a + ib and c + id */
+
+long double _Complex
+__mulxc3(long double __a, long double __b, long double __c, long double __d)
+{
+ long double __ac = __a * __c;
+ long double __bd = __b * __d;
+ long double __ad = __a * __d;
+ long double __bc = __b * __c;
+ long double _Complex z;
+ __real__ z = __ac - __bd;
+ __imag__ z = __ad + __bc;
+ if (isnan(__real__ z) && isnan(__imag__ z))
+ {
+ int __recalc = 0;
+ if (isinf(__a) || isinf(__b))
+ {
+ __a = copysignl(isinf(__a) ? 1 : 0, __a);
+ __b = copysignl(isinf(__b) ? 1 : 0, __b);
+ if (isnan(__c))
+ __c = copysignl(0, __c);
+ if (isnan(__d))
+ __d = copysignl(0, __d);
+ __recalc = 1;
+ }
+ if (isinf(__c) || isinf(__d))
+ {
+ __c = copysignl(isinf(__c) ? 1 : 0, __c);
+ __d = copysignl(isinf(__d) ? 1 : 0, __d);
+ if (isnan(__a))
+ __a = copysignl(0, __a);
+ if (isnan(__b))
+ __b = copysignl(0, __b);
+ __recalc = 1;
+ }
+ if (!__recalc && (isinf(__ac) || isinf(__bd) ||
+ isinf(__ad) || isinf(__bc)))
+ {
+ if (isnan(__a))
+ __a = copysignl(0, __a);
+ if (isnan(__b))
+ __b = copysignl(0, __b);
+ if (isnan(__c))
+ __c = copysignl(0, __c);
+ if (isnan(__d))
+ __d = copysignl(0, __d);
+ __recalc = 1;
+ }
+ if (__recalc)
+ {
+ __real__ z = INFINITY * (__a * __c - __b * __d);
+ __imag__ z = INFINITY * (__a * __d + __b * __c);
+ }
+ }
+ return z;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/negdf2.c b/contrib/compiler-rt/lib/negdf2.c
new file mode 100644
index 0000000..527b068
--- /dev/null
+++ b/contrib/compiler-rt/lib/negdf2.c
@@ -0,0 +1,19 @@
+//===-- lib/negdf2.c - double-precision negation ------------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements double-precision soft-float negation.
+//
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __negdf2(fp_t a) {
+ return fromRep(toRep(a) ^ signBit);
+}
diff --git a/contrib/compiler-rt/lib/negdi2.c b/contrib/compiler-rt/lib/negdi2.c
new file mode 100644
index 0000000..707b0dd
--- /dev/null
+++ b/contrib/compiler-rt/lib/negdi2.c
@@ -0,0 +1,26 @@
+/* ===-- negdi2.c - Implement __negdi2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __negdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: -a */
+
+di_int
+__negdi2(di_int a)
+{
+ /* Note: this routine is here for API compatibility; any sane compiler
+ * should expand it inline.
+ */
+ return -a;
+}
diff --git a/contrib/compiler-rt/lib/negsf2.c b/contrib/compiler-rt/lib/negsf2.c
new file mode 100644
index 0000000..5e91e87
--- /dev/null
+++ b/contrib/compiler-rt/lib/negsf2.c
@@ -0,0 +1,19 @@
+//===-- lib/negsf2.c - single-precision negation ------------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements single-precision soft-float negation.
+//
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+fp_t __negsf2(fp_t a) {
+ return fromRep(toRep(a) ^ signBit);
+}
diff --git a/contrib/compiler-rt/lib/negti2.c b/contrib/compiler-rt/lib/negti2.c
new file mode 100644
index 0000000..6ce6a04
--- /dev/null
+++ b/contrib/compiler-rt/lib/negti2.c
@@ -0,0 +1,30 @@
+/* ===-- negti2.c - Implement __negti2 -------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __negti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: -a */
+
+ti_int
+__negti2(ti_int a)
+{
+ /* Note: this routine is here for API compatibility; any sane compiler
+ * should expand it inline.
+ */
+ return -a;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/negvdi2.c b/contrib/compiler-rt/lib/negvdi2.c
new file mode 100644
index 0000000..0baf377
--- /dev/null
+++ b/contrib/compiler-rt/lib/negvdi2.c
@@ -0,0 +1,29 @@
+/* ===-- negvdi2.c - Implement __negvdi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __negvdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: -a */
+
+/* Effects: aborts if -a overflows */
+
+di_int
+__negvdi2(di_int a)
+{
+ const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT)-1);
+ if (a == MIN)
+ compilerrt_abort();
+ return -a;
+}
diff --git a/contrib/compiler-rt/lib/negvsi2.c b/contrib/compiler-rt/lib/negvsi2.c
new file mode 100644
index 0000000..e5a36a5
--- /dev/null
+++ b/contrib/compiler-rt/lib/negvsi2.c
@@ -0,0 +1,29 @@
+/* ===-- negvsi2.c - Implement __negvsi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __negvsi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: -a */
+
+/* Effects: aborts if -a overflows */
+
+si_int
+__negvsi2(si_int a)
+{
+ const si_int MIN = (si_int)1 << ((int)(sizeof(si_int) * CHAR_BIT)-1);
+ if (a == MIN)
+ compilerrt_abort();
+ return -a;
+}
diff --git a/contrib/compiler-rt/lib/negvti2.c b/contrib/compiler-rt/lib/negvti2.c
new file mode 100644
index 0000000..d56e1e3
--- /dev/null
+++ b/contrib/compiler-rt/lib/negvti2.c
@@ -0,0 +1,33 @@
+/*===-- negvti2.c - Implement __negvti2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ *===----------------------------------------------------------------------===
+ *
+ *This file implements __negvti2 for the compiler_rt library.
+ *
+ *===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: -a */
+
+/* Effects: aborts if -a overflows */
+
+ti_int
+__negvti2(ti_int a)
+{
+ const ti_int MIN = (ti_int)1 << ((int)(sizeof(ti_int) * CHAR_BIT)-1);
+ if (a == MIN)
+ compilerrt_abort();
+ return -a;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/paritydi2.c b/contrib/compiler-rt/lib/paritydi2.c
new file mode 100644
index 0000000..90e5559
--- /dev/null
+++ b/contrib/compiler-rt/lib/paritydi2.c
@@ -0,0 +1,27 @@
+/* ===-- paritydi2.c - Implement __paritydi2 -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __paritydi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: 1 if number of bits is odd else returns 0 */
+
+si_int __paritysi2(si_int a);
+
+si_int
+__paritydi2(di_int a)
+{
+ dwords x;
+ x.all = a;
+ return __paritysi2(x.s.high ^ x.s.low);
+}
diff --git a/contrib/compiler-rt/lib/paritysi2.c b/contrib/compiler-rt/lib/paritysi2.c
new file mode 100644
index 0000000..ba05782
--- /dev/null
+++ b/contrib/compiler-rt/lib/paritysi2.c
@@ -0,0 +1,27 @@
+/* ===-- paritysi2.c - Implement __paritysi2 -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __paritysi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: 1 if number of bits is odd else returns 0 */
+
+si_int
+__paritysi2(si_int a)
+{
+ su_int x = (su_int)a;
+ x ^= x >> 16;
+ x ^= x >> 8;
+ x ^= x >> 4;
+ return (0x6996 >> (x & 0xF)) & 1;
+}
diff --git a/contrib/compiler-rt/lib/parityti2.c b/contrib/compiler-rt/lib/parityti2.c
new file mode 100644
index 0000000..650d417
--- /dev/null
+++ b/contrib/compiler-rt/lib/parityti2.c
@@ -0,0 +1,31 @@
+/* ===-- parityti2.c - Implement __parityti2 -------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __parityti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: 1 if number of bits is odd else returns 0 */
+
+si_int __paritydi2(di_int a);
+
+si_int
+__parityti2(ti_int a)
+{
+ twords x;
+ x.all = a;
+ return __paritydi2(x.s.high ^ x.s.low);
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/popcountdi2.c b/contrib/compiler-rt/lib/popcountdi2.c
new file mode 100644
index 0000000..78b6d88
--- /dev/null
+++ b/contrib/compiler-rt/lib/popcountdi2.c
@@ -0,0 +1,36 @@
+/* ===-- popcountdi2.c - Implement __popcountdi2 ----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __popcountdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: count of 1 bits */
+
+si_int
+__popcountdi2(di_int a)
+{
+ du_int x2 = (du_int)a;
+ x2 = x2 - ((x2 >> 1) & 0x5555555555555555uLL);
+ /* Every 2 bits holds the sum of every pair of bits (32) */
+ x2 = ((x2 >> 2) & 0x3333333333333333uLL) + (x2 & 0x3333333333333333uLL);
+ /* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (16) */
+ x2 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0FuLL;
+ /* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (8) */
+ su_int x = (su_int)(x2 + (x2 >> 32));
+ /* The lower 32 bits hold four 16 bit sums (5 significant bits). */
+ /* Upper 32 bits are garbage */
+ x = x + (x >> 16);
+ /* The lower 16 bits hold two 32 bit sums (6 significant bits). */
+ /* Upper 16 bits are garbage */
+ return (x + (x >> 8)) & 0x0000007F; /* (7 significant bits) */
+}
diff --git a/contrib/compiler-rt/lib/popcountsi2.c b/contrib/compiler-rt/lib/popcountsi2.c
new file mode 100644
index 0000000..4f092ee
--- /dev/null
+++ b/contrib/compiler-rt/lib/popcountsi2.c
@@ -0,0 +1,33 @@
+/* ===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __popcountsi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: count of 1 bits */
+
+si_int
+__popcountsi2(si_int a)
+{
+ su_int x = (su_int)a;
+ x = x - ((x >> 1) & 0x55555555);
+ /* Every 2 bits holds the sum of every pair of bits */
+ x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
+ /* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) */
+ x = (x + (x >> 4)) & 0x0F0F0F0F;
+ /* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) */
+ x = (x + (x >> 16));
+ /* The lower 16 bits hold two 8 bit sums (5 significant bits).*/
+ /* Upper 16 bits are garbage */
+ return (x + (x >> 8)) & 0x0000003F; /* (6 significant bits) */
+}
diff --git a/contrib/compiler-rt/lib/popcountti2.c b/contrib/compiler-rt/lib/popcountti2.c
new file mode 100644
index 0000000..16f89b7
--- /dev/null
+++ b/contrib/compiler-rt/lib/popcountti2.c
@@ -0,0 +1,44 @@
+/* ===-- popcountti2.c - Implement __popcountti2 ----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __popcountti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: count of 1 bits */
+
+si_int
+__popcountti2(ti_int a)
+{
+ tu_int x3 = (tu_int)a;
+ x3 = x3 - ((x3 >> 1) & (((tu_int)0x5555555555555555uLL << 64) |
+ 0x5555555555555555uLL));
+ /* Every 2 bits holds the sum of every pair of bits (64) */
+ x3 = ((x3 >> 2) & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL))
+ + (x3 & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL));
+ /* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (32) */
+ x3 = (x3 + (x3 >> 4))
+ & (((tu_int)0x0F0F0F0F0F0F0F0FuLL << 64) | 0x0F0F0F0F0F0F0F0FuLL);
+ /* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (16) */
+ du_int x2 = (du_int)(x3 + (x3 >> 64));
+ /* Every 8 bits holds the sum of every 8-set of bits (5 significant bits) (8) */
+ su_int x = (su_int)(x2 + (x2 >> 32));
+ /* Every 8 bits holds the sum of every 8-set of bits (6 significant bits) (4) */
+ x = x + (x >> 16);
+ /* Every 8 bits holds the sum of every 8-set of bits (7 significant bits) (2) */
+ /* Upper 16 bits are garbage */
+ return (x + (x >> 8)) & 0xFF; /* (8 significant bits) */
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/powidf2.c b/contrib/compiler-rt/lib/powidf2.c
new file mode 100644
index 0000000..37972b6
--- /dev/null
+++ b/contrib/compiler-rt/lib/powidf2.c
@@ -0,0 +1,34 @@
+/* ===-- powidf2.cpp - Implement __powidf2 ---------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __powidf2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a ^ b */
+
+double
+__powidf2(double a, si_int b)
+{
+ const int recip = b < 0;
+ double r = 1;
+ while (1)
+ {
+ if (b & 1)
+ r *= a;
+ b /= 2;
+ if (b == 0)
+ break;
+ a *= a;
+ }
+ return recip ? 1/r : r;
+}
diff --git a/contrib/compiler-rt/lib/powisf2.c b/contrib/compiler-rt/lib/powisf2.c
new file mode 100644
index 0000000..ace08c2
--- /dev/null
+++ b/contrib/compiler-rt/lib/powisf2.c
@@ -0,0 +1,34 @@
+/*===-- powisf2.cpp - Implement __powisf2 ---------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __powisf2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a ^ b */
+
+float
+__powisf2(float a, si_int b)
+{
+ const int recip = b < 0;
+ float r = 1;
+ while (1)
+ {
+ if (b & 1)
+ r *= a;
+ b /= 2;
+ if (b == 0)
+ break;
+ a *= a;
+ }
+ return recip ? 1/r : r;
+}
diff --git a/contrib/compiler-rt/lib/powitf2.c b/contrib/compiler-rt/lib/powitf2.c
new file mode 100644
index 0000000..3dacbf6
--- /dev/null
+++ b/contrib/compiler-rt/lib/powitf2.c
@@ -0,0 +1,38 @@
+/* ===-- powitf2.cpp - Implement __powitf2 ---------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __powitf2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if _ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: a ^ b */
+
+long double
+__powitf2(long double a, si_int b)
+{
+ const int recip = b < 0;
+ long double r = 1;
+ while (1)
+ {
+ if (b & 1)
+ r *= a;
+ b /= 2;
+ if (b == 0)
+ break;
+ a *= a;
+ }
+ return recip ? 1/r : r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/powixf2.c b/contrib/compiler-rt/lib/powixf2.c
new file mode 100644
index 0000000..1a816e9
--- /dev/null
+++ b/contrib/compiler-rt/lib/powixf2.c
@@ -0,0 +1,38 @@
+/* ===-- powixf2.cpp - Implement __powixf2 ---------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __powixf2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if !_ARCH_PPC
+
+#include "int_lib.h"
+
+/* Returns: a ^ b */
+
+long double
+__powixf2(long double a, si_int b)
+{
+ const int recip = b < 0;
+ long double r = 1;
+ while (1)
+ {
+ if (b & 1)
+ r *= a;
+ b /= 2;
+ if (b == 0)
+ break;
+ a *= a;
+ }
+ return recip ? 1/r : r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/ppc/DD.h b/contrib/compiler-rt/lib/ppc/DD.h
new file mode 100644
index 0000000..9ecd1f5
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/DD.h
@@ -0,0 +1,46 @@
+#ifndef __DD_HEADER
+#define __DD_HEADER
+
+#include <stdint.h>
+
+typedef union {
+ long double ld;
+ struct {
+ double hi;
+ double lo;
+ }s;
+}DD;
+
+typedef union {
+ double d;
+ uint64_t x;
+} doublebits;
+
+#define LOWORDER(xy,xHi,xLo,yHi,yLo) \
+ (((((xHi)*(yHi) - (xy)) + (xHi)*(yLo)) + (xLo)*(yHi)) + (xLo)*(yLo))
+
+static inline double __attribute__((always_inline))
+fabs(double x)
+{
+ doublebits result = { .d = x };
+ result.x &= UINT64_C(0x7fffffffffffffff);
+ return result.d;
+}
+
+static inline double __attribute__((always_inline))
+high26bits(double x)
+{
+ doublebits result = { .d = x };
+ result.x &= UINT64_C(0xfffffffff8000000);
+ return result.d;
+}
+
+static inline int __attribute__((always_inline))
+different_sign(double x, double y)
+{
+ doublebits xsignbit = { .d = x }, ysignbit = { .d = y };
+ int result = (int)(xsignbit.x >> 63) ^ (int)(ysignbit.x >> 63);
+ return result;
+}
+
+#endif /* __DD_HEADER */
diff --git a/contrib/compiler-rt/lib/ppc/divtc3.c b/contrib/compiler-rt/lib/ppc/divtc3.c
new file mode 100644
index 0000000..d41f621
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/divtc3.c
@@ -0,0 +1,93 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+#include "DD.h"
+#include <math.h>
+
+#if !defined(INFINITY) && defined(HUGE_VAL)
+#define INFINITY HUGE_VAL
+#endif /* INFINITY */
+
+#define makeFinite(x) { \
+ (x).s.hi = __builtin_copysign(isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \
+ (x).s.lo = 0.0; \
+ }
+
+long double __gcc_qadd(long double, long double);
+long double __gcc_qsub(long double, long double);
+long double __gcc_qmul(long double, long double);
+long double __gcc_qdiv(long double, long double);
+
+long double _Complex
+__divtc3(long double a, long double b, long double c, long double d)
+{
+ DD cDD = { .ld = c };
+ DD dDD = { .ld = d };
+
+ int ilogbw = 0;
+ const double logbw = logb(__builtin_fmax( __builtin_fabs(cDD.s.hi), __builtin_fabs(dDD.s.hi) ));
+
+ if (isfinite(logbw))
+ {
+ ilogbw = (int)logbw;
+
+ cDD.s.hi = scalbn(cDD.s.hi, -ilogbw);
+ cDD.s.lo = scalbn(cDD.s.lo, -ilogbw);
+ dDD.s.hi = scalbn(dDD.s.hi, -ilogbw);
+ dDD.s.lo = scalbn(dDD.s.lo, -ilogbw);
+ }
+
+ const long double denom = __gcc_qadd(__gcc_qmul(cDD.ld, cDD.ld), __gcc_qmul(dDD.ld, dDD.ld));
+ const long double realNumerator = __gcc_qadd(__gcc_qmul(a,cDD.ld), __gcc_qmul(b,dDD.ld));
+ const long double imagNumerator = __gcc_qsub(__gcc_qmul(b,cDD.ld), __gcc_qmul(a,dDD.ld));
+
+ DD real = { .ld = __gcc_qdiv(realNumerator, denom) };
+ DD imag = { .ld = __gcc_qdiv(imagNumerator, denom) };
+
+ real.s.hi = scalbn(real.s.hi, -ilogbw);
+ real.s.lo = scalbn(real.s.lo, -ilogbw);
+ imag.s.hi = scalbn(imag.s.hi, -ilogbw);
+ imag.s.lo = scalbn(imag.s.lo, -ilogbw);
+
+ if (isnan(real.s.hi) && isnan(imag.s.hi))
+ {
+ DD aDD = { .ld = a };
+ DD bDD = { .ld = b };
+ DD rDD = { .ld = denom };
+
+ if ((rDD.s.hi == 0.0) && (!isnan(aDD.s.hi) || !isnan(bDD.s.hi)))
+ {
+ real.s.hi = __builtin_copysign(INFINITY,cDD.s.hi) * aDD.s.hi;
+ real.s.lo = 0.0;
+ imag.s.hi = __builtin_copysign(INFINITY,cDD.s.hi) * bDD.s.hi;
+ imag.s.lo = 0.0;
+ }
+
+ else if ((isinf(aDD.s.hi) || isinf(bDD.s.hi)) && isfinite(cDD.s.hi) && isfinite(dDD.s.hi))
+ {
+ makeFinite(aDD);
+ makeFinite(bDD);
+ real.s.hi = INFINITY * (aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi);
+ real.s.lo = 0.0;
+ imag.s.hi = INFINITY * (bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi);
+ imag.s.lo = 0.0;
+ }
+
+ else if ((isinf(cDD.s.hi) || isinf(dDD.s.hi)) && isfinite(aDD.s.hi) && isfinite(bDD.s.hi))
+ {
+ makeFinite(cDD);
+ makeFinite(dDD);
+ real.s.hi = __builtin_copysign(0.0,(aDD.s.hi*cDD.s.hi + bDD.s.hi*dDD.s.hi));
+ real.s.lo = 0.0;
+ imag.s.hi = __builtin_copysign(0.0,(bDD.s.hi*cDD.s.hi - aDD.s.hi*dDD.s.hi));
+ imag.s.lo = 0.0;
+ }
+ }
+
+ long double _Complex z;
+ __real__ z = real.ld;
+ __imag__ z = imag.ld;
+
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/ppc/fixtfdi.c b/contrib/compiler-rt/lib/ppc/fixtfdi.c
new file mode 100644
index 0000000..fa113a0
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/fixtfdi.c
@@ -0,0 +1,104 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* int64_t __fixunstfdi(long double x);
+ * This file implements the PowerPC 128-bit double-double -> int64_t conversion
+ */
+
+#include "DD.h"
+#include <stdint.h>
+
+uint64_t __fixtfdi(long double input)
+{
+ const DD x = { .ld = input };
+ const doublebits hibits = { .d = x.s.hi };
+
+ const uint32_t absHighWord = (uint32_t)(hibits.x >> 32) & UINT32_C(0x7fffffff);
+ const uint32_t absHighWordMinusOne = absHighWord - UINT32_C(0x3ff00000);
+
+ /* If (1.0 - tiny) <= input < 0x1.0p63: */
+ if (UINT32_C(0x03f00000) > absHighWordMinusOne)
+ {
+ /* Do an unsigned conversion of the absolute value, then restore the sign. */
+ const int unbiasedHeadExponent = absHighWordMinusOne >> 20;
+
+ int64_t result = hibits.x & INT64_C(0x000fffffffffffff); /* mantissa(hi) */
+ result |= INT64_C(0x0010000000000000); /* matissa(hi) with implicit bit */
+ result <<= 10; /* mantissa(hi) with one zero preceeding bit. */
+
+ const int64_t hiNegationMask = ((int64_t)(hibits.x)) >> 63;
+
+ /* If the tail is non-zero, we need to patch in the tail bits. */
+ if (0.0 != x.s.lo)
+ {
+ const doublebits lobits = { .d = x.s.lo };
+ int64_t tailMantissa = lobits.x & INT64_C(0x000fffffffffffff);
+ tailMantissa |= INT64_C(0x0010000000000000);
+
+ /* At this point we have the mantissa of |tail| */
+ /* We need to negate it if head and tail have different signs. */
+ const int64_t loNegationMask = ((int64_t)(lobits.x)) >> 63;
+ const int64_t negationMask = loNegationMask ^ hiNegationMask;
+ tailMantissa = (tailMantissa ^ negationMask) - negationMask;
+
+ /* Now we have the mantissa of tail as a signed 2s-complement integer */
+
+ const int biasedTailExponent = (int)(lobits.x >> 52) & 0x7ff;
+
+ /* Shift the tail mantissa into the right position, accounting for the
+ * bias of 10 that we shifted the head mantissa by.
+ */
+ tailMantissa >>= (unbiasedHeadExponent - (biasedTailExponent - (1023 - 10)));
+
+ result += tailMantissa;
+ }
+
+ result >>= (62 - unbiasedHeadExponent);
+
+ /* Restore the sign of the result and return */
+ result = (result ^ hiNegationMask) - hiNegationMask;
+ return result;
+
+ }
+
+ /* Edge cases handled here: */
+
+ /* |x| < 1, result is zero. */
+ if (1.0 > __builtin_fabs(x.s.hi))
+ return INT64_C(0);
+
+ /* x very close to INT64_MIN, care must be taken to see which side we are on. */
+ if (x.s.hi == -0x1.0p63) {
+
+ int64_t result = INT64_MIN;
+
+ if (0.0 < x.s.lo)
+ {
+ /* If the tail is positive, the correct result is something other than INT64_MIN.
+ * we'll need to figure out what it is.
+ */
+
+ const doublebits lobits = { .d = x.s.lo };
+ int64_t tailMantissa = lobits.x & INT64_C(0x000fffffffffffff);
+ tailMantissa |= INT64_C(0x0010000000000000);
+
+ /* Now we negate the tailMantissa */
+ tailMantissa = (tailMantissa ^ INT64_C(-1)) + INT64_C(1);
+
+ /* And shift it by the appropriate amount */
+ const int biasedTailExponent = (int)(lobits.x >> 52) & 0x7ff;
+ tailMantissa >>= 1075 - biasedTailExponent;
+
+ result -= tailMantissa;
+ }
+
+ return result;
+ }
+
+ /* Signed overflows, infinities, and NaNs */
+ if (x.s.hi > 0.0)
+ return INT64_MAX;
+ else
+ return INT64_MIN;
+}
diff --git a/contrib/compiler-rt/lib/ppc/fixunstfdi.c b/contrib/compiler-rt/lib/ppc/fixunstfdi.c
new file mode 100644
index 0000000..1fb5248
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/fixunstfdi.c
@@ -0,0 +1,60 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* uint64_t __fixunstfdi(long double x); */
+/* This file implements the PowerPC 128-bit double-double -> uint64_t conversion */
+
+#include "DD.h"
+#include <stdint.h>
+
+uint64_t __fixunstfdi(long double input)
+{
+ const DD x = { .ld = input };
+ const doublebits hibits = { .d = x.s.hi };
+
+ const uint32_t highWordMinusOne = (uint32_t)(hibits.x >> 32) - UINT32_C(0x3ff00000);
+
+ /* If (1.0 - tiny) <= input < 0x1.0p64: */
+ if (UINT32_C(0x04000000) > highWordMinusOne)
+ {
+ const int unbiasedHeadExponent = highWordMinusOne >> 20;
+
+ uint64_t result = hibits.x & UINT64_C(0x000fffffffffffff); /* mantissa(hi) */
+ result |= UINT64_C(0x0010000000000000); /* matissa(hi) with implicit bit */
+ result <<= 11; /* mantissa(hi) left aligned in the int64 field. */
+
+ /* If the tail is non-zero, we need to patch in the tail bits. */
+ if (0.0 != x.s.lo)
+ {
+ const doublebits lobits = { .d = x.s.lo };
+ int64_t tailMantissa = lobits.x & INT64_C(0x000fffffffffffff);
+ tailMantissa |= INT64_C(0x0010000000000000);
+
+ /* At this point we have the mantissa of |tail| */
+
+ const int64_t negationMask = ((int64_t)(lobits.x)) >> 63;
+ tailMantissa = (tailMantissa ^ negationMask) - negationMask;
+
+ /* Now we have the mantissa of tail as a signed 2s-complement integer */
+
+ const int biasedTailExponent = (int)(lobits.x >> 52) & 0x7ff;
+
+ /* Shift the tail mantissa into the right position, accounting for the
+ * bias of 11 that we shifted the head mantissa by.
+ */
+ tailMantissa >>= (unbiasedHeadExponent - (biasedTailExponent - (1023 - 11)));
+
+ result += tailMantissa;
+ }
+
+ result >>= (63 - unbiasedHeadExponent);
+ return result;
+ }
+
+ /* Edge cases are handled here, with saturation. */
+ if (1.0 > x.s.hi)
+ return UINT64_C(0);
+ else
+ return UINT64_MAX;
+}
diff --git a/contrib/compiler-rt/lib/ppc/floatditf.c b/contrib/compiler-rt/lib/ppc/floatditf.c
new file mode 100644
index 0000000..ed23dc8
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/floatditf.c
@@ -0,0 +1,37 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __floatditf(long long x); */
+/* This file implements the PowerPC long long -> long double conversion */
+
+#include "DD.h"
+#include <stdint.h>
+
+long double __floatditf(int64_t a) {
+
+ static const double twop32 = 0x1.0p32;
+ static const double twop52 = 0x1.0p52;
+
+ doublebits low = { .d = twop52 };
+ low.x |= a & UINT64_C(0x00000000ffffffff); /* 0x1.0p52 + low 32 bits of a. */
+
+ const double high_addend = (double)((int32_t)(a >> 32))*twop32 - twop52;
+
+ /* At this point, we have two double precision numbers
+ * high_addend and low.d, and we wish to return their sum
+ * as a canonicalized long double:
+ */
+
+ /* This implementation sets the inexact flag spuriously.
+ * This could be avoided, but at some substantial cost.
+ */
+
+ DD result;
+
+ result.s.hi = high_addend + low.d;
+ result.s.lo = (high_addend - result.s.hi) + low.d;
+
+ return result.ld;
+
+}
diff --git a/contrib/compiler-rt/lib/ppc/floatunditf.c b/contrib/compiler-rt/lib/ppc/floatunditf.c
new file mode 100644
index 0000000..20a3b71
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/floatunditf.c
@@ -0,0 +1,42 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __floatunditf(unsigned long long x); */
+/* This file implements the PowerPC unsigned long long -> long double conversion */
+
+#include "DD.h"
+#include <stdint.h>
+
+long double __floatunditf(uint64_t a) {
+
+ /* Begins with an exact copy of the code from __floatundidf */
+
+ static const double twop52 = 0x1.0p52;
+ static const double twop84 = 0x1.0p84;
+ static const double twop84_plus_twop52 = 0x1.00000001p84;
+
+ doublebits high = { .d = twop84 };
+ doublebits low = { .d = twop52 };
+
+ high.x |= a >> 32; /* 0x1.0p84 + high 32 bits of a */
+ low.x |= a & UINT64_C(0x00000000ffffffff); /* 0x1.0p52 + low 32 bits of a */
+
+ const double high_addend = high.d - twop84_plus_twop52;
+
+ /* At this point, we have two double precision numbers
+ * high_addend and low.d, and we wish to return their sum
+ * as a canonicalized long double:
+ */
+
+ /* This implementation sets the inexact flag spuriously. */
+ /* This could be avoided, but at some substantial cost. */
+
+ DD result;
+
+ result.s.hi = high_addend + low.d;
+ result.s.lo = (high_addend - result.s.hi) + low.d;
+
+ return result.ld;
+
+}
diff --git a/contrib/compiler-rt/lib/ppc/gcc_qadd.c b/contrib/compiler-rt/lib/ppc/gcc_qadd.c
new file mode 100644
index 0000000..c388c7e
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/gcc_qadd.c
@@ -0,0 +1,76 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __gcc_qadd(long double x, long double y);
+ * This file implements the PowerPC 128-bit double-double add operation.
+ * This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
+ */
+
+#include "DD.h"
+
+long double __gcc_qadd(long double x, long double y)
+{
+ static const uint32_t infinityHi = UINT32_C(0x7ff00000);
+
+ DD dst = { .ld = x }, src = { .ld = y };
+
+ register double A = dst.s.hi, a = dst.s.lo,
+ B = src.s.hi, b = src.s.lo;
+
+ /* If both operands are zero: */
+ if ((A == 0.0) && (B == 0.0)) {
+ dst.s.hi = A + B;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ /* If either operand is NaN or infinity: */
+ const doublebits abits = { .d = A };
+ const doublebits bbits = { .d = B };
+ if ((((uint32_t)(abits.x >> 32) & infinityHi) == infinityHi) ||
+ (((uint32_t)(bbits.x >> 32) & infinityHi) == infinityHi)) {
+ dst.s.hi = A + B;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ /* If the computation overflows: */
+ /* This may be playing things a little bit fast and loose, but it will do for a start. */
+ const double testForOverflow = A + (B + (a + b));
+ const doublebits testbits = { .d = testForOverflow };
+ if (((uint32_t)(testbits.x >> 32) & infinityHi) == infinityHi) {
+ dst.s.hi = testForOverflow;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ double H, h;
+ double T, t;
+ double W, w;
+ double Y;
+
+ H = B + (A - (A + B));
+ T = b + (a - (a + b));
+ h = A + (B - (A + B));
+ t = a + (b - (a + b));
+
+ if (fabs(A) <= fabs(B))
+ w = (a + b) + h;
+ else
+ w = (a + b) + H;
+
+ W = (A + B) + w;
+ Y = (A + B) - W;
+ Y += w;
+
+ if (fabs(a) <= fabs(b))
+ w = t + Y;
+ else
+ w = T + Y;
+
+ dst.s.hi = Y = W + w;
+ dst.s.lo = (W - Y) + w;
+
+ return dst.ld;
+}
diff --git a/contrib/compiler-rt/lib/ppc/gcc_qdiv.c b/contrib/compiler-rt/lib/ppc/gcc_qdiv.c
new file mode 100644
index 0000000..70aa00b
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/gcc_qdiv.c
@@ -0,0 +1,55 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __gcc_qdiv(long double x, long double y);
+ * This file implements the PowerPC 128-bit double-double division operation.
+ * This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
+ */
+
+#include "DD.h"
+
+long double __gcc_qdiv(long double a, long double b)
+{
+ static const uint32_t infinityHi = UINT32_C(0x7ff00000);
+ DD dst = { .ld = a }, src = { .ld = b };
+
+ register double x = dst.s.hi, x1 = dst.s.lo,
+ y = src.s.hi, y1 = src.s.lo;
+
+ double yHi, yLo, qHi, qLo;
+ double yq, tmp, q;
+
+ q = x / y;
+
+ /* Detect special cases */
+ if (q == 0.0) {
+ dst.s.hi = q;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ const doublebits qBits = { .d = q };
+ if (((uint32_t)(qBits.x >> 32) & infinityHi) == infinityHi) {
+ dst.s.hi = q;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ yHi = high26bits(y);
+ qHi = high26bits(q);
+
+ yq = y * q;
+ yLo = y - yHi;
+ qLo = q - qHi;
+
+ tmp = LOWORDER(yq, yHi, yLo, qHi, qLo);
+ tmp = (x - yq) - tmp;
+ tmp = ((tmp + x1) - y1 * q) / y;
+ x = q + tmp;
+
+ dst.s.lo = (q - x) + tmp;
+ dst.s.hi = x;
+
+ return dst.ld;
+}
diff --git a/contrib/compiler-rt/lib/ppc/gcc_qmul.c b/contrib/compiler-rt/lib/ppc/gcc_qmul.c
new file mode 100644
index 0000000..fb4c516
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/gcc_qmul.c
@@ -0,0 +1,53 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __gcc_qmul(long double x, long double y);
+ * This file implements the PowerPC 128-bit double-double multiply operation.
+ * This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
+ */
+
+#include "DD.h"
+
+long double __gcc_qmul(long double x, long double y)
+{
+ static const uint32_t infinityHi = UINT32_C(0x7ff00000);
+ DD dst = { .ld = x }, src = { .ld = y };
+
+ register double A = dst.s.hi, a = dst.s.lo,
+ B = src.s.hi, b = src.s.lo;
+
+ double aHi, aLo, bHi, bLo;
+ double ab, tmp, tau;
+
+ ab = A * B;
+
+ /* Detect special cases */
+ if (ab == 0.0) {
+ dst.s.hi = ab;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ const doublebits abBits = { .d = ab };
+ if (((uint32_t)(abBits.x >> 32) & infinityHi) == infinityHi) {
+ dst.s.hi = ab;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ /* Generic cases handled here. */
+ aHi = high26bits(A);
+ bHi = high26bits(B);
+ aLo = A - aHi;
+ bLo = B - bHi;
+
+ tmp = LOWORDER(ab, aHi, aLo, bHi, bLo);
+ tmp += (A * b + a * B);
+ tau = ab + tmp;
+
+ dst.s.lo = (ab - tau) + tmp;
+ dst.s.hi = tau;
+
+ return dst.ld;
+}
diff --git a/contrib/compiler-rt/lib/ppc/gcc_qsub.c b/contrib/compiler-rt/lib/ppc/gcc_qsub.c
new file mode 100644
index 0000000..4f1f7ac
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/gcc_qsub.c
@@ -0,0 +1,76 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __gcc_qsub(long double x, long double y);
+ * This file implements the PowerPC 128-bit double-double add operation.
+ * This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
+ */
+
+#include "DD.h"
+
+long double __gcc_qsub(long double x, long double y)
+{
+ static const uint32_t infinityHi = UINT32_C(0x7ff00000);
+
+ DD dst = { .ld = x }, src = { .ld = y };
+
+ register double A = dst.s.hi, a = dst.s.lo,
+ B = -src.s.hi, b = -src.s.lo;
+
+ /* If both operands are zero: */
+ if ((A == 0.0) && (B == 0.0)) {
+ dst.s.hi = A + B;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ /* If either operand is NaN or infinity: */
+ const doublebits abits = { .d = A };
+ const doublebits bbits = { .d = B };
+ if ((((uint32_t)(abits.x >> 32) & infinityHi) == infinityHi) ||
+ (((uint32_t)(bbits.x >> 32) & infinityHi) == infinityHi)) {
+ dst.s.hi = A + B;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ /* If the computation overflows: */
+ /* This may be playing things a little bit fast and loose, but it will do for a start. */
+ const double testForOverflow = A + (B + (a + b));
+ const doublebits testbits = { .d = testForOverflow };
+ if (((uint32_t)(testbits.x >> 32) & infinityHi) == infinityHi) {
+ dst.s.hi = testForOverflow;
+ dst.s.lo = 0.0;
+ return dst.ld;
+ }
+
+ double H, h;
+ double T, t;
+ double W, w;
+ double Y;
+
+ H = B + (A - (A + B));
+ T = b + (a - (a + b));
+ h = A + (B - (A + B));
+ t = a + (b - (a + b));
+
+ if (fabs(A) <= fabs(B))
+ w = (a + b) + h;
+ else
+ w = (a + b) + H;
+
+ W = (A + B) + w;
+ Y = (A + B) - W;
+ Y += w;
+
+ if (fabs(a) <= fabs(b))
+ w = t + Y;
+ else
+ w = T + Y;
+
+ dst.s.hi = Y = W + w;
+ dst.s.lo = (W - Y) + w;
+
+ return dst.ld;
+}
diff --git a/contrib/compiler-rt/lib/ppc/multc3.c b/contrib/compiler-rt/lib/ppc/multc3.c
new file mode 100644
index 0000000..9d17a2c
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/multc3.c
@@ -0,0 +1,97 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+#include "DD.h"
+#include <math.h>
+
+#if !defined(INFINITY) && defined(HUGE_VAL)
+#define INFINITY HUGE_VAL
+#endif /* INFINITY */
+
+#define makeFinite(x) { \
+ (x).s.hi = __builtin_copysign(isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \
+ (x).s.lo = 0.0; \
+ }
+
+#define zeroNaN(x) { \
+ if (isnan((x).s.hi)) { \
+ (x).s.hi = __builtin_copysign(0.0, (x).s.hi); \
+ (x).s.lo = 0.0; \
+ } \
+ }
+
+long double __gcc_qadd(long double, long double);
+long double __gcc_qsub(long double, long double);
+long double __gcc_qmul(long double, long double);
+
+long double _Complex
+__multc3(long double a, long double b, long double c, long double d)
+{
+ long double ac = __gcc_qmul(a,c);
+ long double bd = __gcc_qmul(b,d);
+ long double ad = __gcc_qmul(a,d);
+ long double bc = __gcc_qmul(b,c);
+
+ DD real = { .ld = __gcc_qsub(ac,bd) };
+ DD imag = { .ld = __gcc_qadd(ad,bc) };
+
+ if (isnan(real.s.hi) && isnan(imag.s.hi))
+ {
+ int recalc = 0;
+
+ DD aDD = { .ld = a };
+ DD bDD = { .ld = b };
+ DD cDD = { .ld = c };
+ DD dDD = { .ld = d };
+
+ if (isinf(aDD.s.hi) || isinf(bDD.s.hi))
+ {
+ makeFinite(aDD);
+ makeFinite(bDD);
+ zeroNaN(cDD);
+ zeroNaN(dDD);
+ recalc = 1;
+ }
+
+ if (isinf(cDD.s.hi) || isinf(dDD.s.hi))
+ {
+ makeFinite(cDD);
+ makeFinite(dDD);
+ zeroNaN(aDD);
+ zeroNaN(bDD);
+ recalc = 1;
+ }
+
+ if (!recalc)
+ {
+ DD acDD = { .ld = ac };
+ DD bdDD = { .ld = bd };
+ DD adDD = { .ld = ad };
+ DD bcDD = { .ld = bc };
+
+ if (isinf(acDD.s.hi) || isinf(bdDD.s.hi) || isinf(adDD.s.hi) || isinf(bcDD.s.hi))
+ {
+ zeroNaN(aDD);
+ zeroNaN(bDD);
+ zeroNaN(cDD);
+ zeroNaN(dDD);
+ recalc = 1;
+ }
+ }
+
+ if (recalc)
+ {
+ real.s.hi = INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi);
+ real.s.lo = 0.0;
+ imag.s.hi = INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi);
+ imag.s.lo = 0.0;
+ }
+ }
+
+ long double _Complex z;
+ __real__ z = real.ld;
+ __imag__ z = imag.ld;
+
+ return z;
+}
diff --git a/contrib/compiler-rt/lib/ppc/restFP.S b/contrib/compiler-rt/lib/ppc/restFP.S
new file mode 100644
index 0000000..00919c8
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/restFP.S
@@ -0,0 +1,43 @@
+//===-- restFP.S - Implement restFP ---------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// Helper function used by compiler to restore ppc floating point registers at
+// the end of the function epilog. This function returns to the address
+// in the LR slot. So a function epilog must branch (b) not branch and link
+// (bl) to this function.
+// If the compiler wants to restore f27..f31, it does a "b restFP+52"
+//
+// This function should never be exported by a shared library. Each linkage
+// unit carries its own copy of this function.
+//
+DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(restFP)
+ lfd f14,-144(r1)
+ lfd f15,-136(r1)
+ lfd f16,-128(r1)
+ lfd f17,-120(r1)
+ lfd f18,-112(r1)
+ lfd f19,-104(r1)
+ lfd f20,-96(r1)
+ lfd f21,-88(r1)
+ lfd f22,-80(r1)
+ lfd f23,-72(r1)
+ lfd f24,-64(r1)
+ lfd f25,-56(r1)
+ lfd f26,-48(r1)
+ lfd f27,-40(r1)
+ lfd f28,-32(r1)
+ lfd f29,-24(r1)
+ lfd f30,-16(r1)
+ lfd f31,-8(r1)
+ lwz r0,8(r1)
+ mtlr r0
+ blr
diff --git a/contrib/compiler-rt/lib/ppc/saveFP.S b/contrib/compiler-rt/lib/ppc/saveFP.S
new file mode 100644
index 0000000..302da6e
--- /dev/null
+++ b/contrib/compiler-rt/lib/ppc/saveFP.S
@@ -0,0 +1,40 @@
+//===-- saveFP.S - Implement saveFP ---------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+//
+// Helper function used by compiler to save ppc floating point registers in
+// function prologs. This routines also saves r0 in the LR slot.
+// If the compiler wants to save f27..f31, it does a "bl saveFP+52"
+//
+// This function should never be exported by a shared library. Each linkage
+// unit carries its own copy of this function.
+//
+DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(saveFP)
+ stfd f14,-144(r1)
+ stfd f15,-136(r1)
+ stfd f16,-128(r1)
+ stfd f17,-120(r1)
+ stfd f18,-112(r1)
+ stfd f19,-104(r1)
+ stfd f20,-96(r1)
+ stfd f21,-88(r1)
+ stfd f22,-80(r1)
+ stfd f23,-72(r1)
+ stfd f24,-64(r1)
+ stfd f25,-56(r1)
+ stfd f26,-48(r1)
+ stfd f27,-40(r1)
+ stfd f28,-32(r1)
+ stfd f29,-24(r1)
+ stfd f30,-16(r1)
+ stfd f31,-8(r1)
+ stw r0,8(r1)
+ blr
diff --git a/contrib/compiler-rt/lib/subvdi3.c b/contrib/compiler-rt/lib/subvdi3.c
new file mode 100644
index 0000000..e4926b8
--- /dev/null
+++ b/contrib/compiler-rt/lib/subvdi3.c
@@ -0,0 +1,37 @@
+/* ===-- subvdi3.c - Implement __subvdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __subvdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a - b */
+
+/* Effects: aborts if a - b overflows */
+
+di_int
+__subvdi3(di_int a, di_int b)
+{
+ di_int s = a - b;
+ if (b >= 0)
+ {
+ if (s > a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s <= a)
+ compilerrt_abort();
+ }
+ return s;
+}
diff --git a/contrib/compiler-rt/lib/subvsi3.c b/contrib/compiler-rt/lib/subvsi3.c
new file mode 100644
index 0000000..ce39c81
--- /dev/null
+++ b/contrib/compiler-rt/lib/subvsi3.c
@@ -0,0 +1,37 @@
+/* ===-- subvsi3.c - Implement __subvsi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __subvsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a - b */
+
+/* Effects: aborts if a - b overflows */
+
+si_int
+__subvsi3(si_int a, si_int b)
+{
+ si_int s = a - b;
+ if (b >= 0)
+ {
+ if (s > a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s <= a)
+ compilerrt_abort();
+ }
+ return s;
+}
diff --git a/contrib/compiler-rt/lib/subvti3.c b/contrib/compiler-rt/lib/subvti3.c
new file mode 100644
index 0000000..55b7925
--- /dev/null
+++ b/contrib/compiler-rt/lib/subvti3.c
@@ -0,0 +1,41 @@
+/* ===-- subvti3.c - Implement __subvti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __subvti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+#include <stdlib.h>
+
+/* Returns: a - b */
+
+/* Effects: aborts if a - b overflows */
+
+ti_int
+__subvti3(ti_int a, ti_int b)
+{
+ ti_int s = a - b;
+ if (b >= 0)
+ {
+ if (s > a)
+ compilerrt_abort();
+ }
+ else
+ {
+ if (s <= a)
+ compilerrt_abort();
+ }
+ return s;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/trampoline_setup.c b/contrib/compiler-rt/lib/trampoline_setup.c
new file mode 100644
index 0000000..a2f49a4
--- /dev/null
+++ b/contrib/compiler-rt/lib/trampoline_setup.c
@@ -0,0 +1,50 @@
+/* ===----- trampoline_setup.c - Implement __trampoline_setup -------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "int_lib.h"
+
+extern void __clear_cache(void* start, void* end);
+
+/*
+ * The ppc compiler generates calls to __trampoline_setup() when creating
+ * trampoline functions on the stack for use with nested functions.
+ * This function creates a custom 40-byte trampoline function on the stack
+ * which loads r11 with a pointer to the outer function's locals
+ * and then jumps to the target nested function.
+ */
+
+#if __ppc__ && !defined(__powerpc64__)
+void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
+ const void* realFunc, void* localsPtr)
+{
+ /* should never happen, but if compiler did not allocate */
+ /* enough space on stack for the trampoline, abort */
+ if ( trampSizeAllocated < 40 )
+ compilerrt_abort();
+
+ /* create trampoline */
+ trampOnStack[0] = 0x7c0802a6; /* mflr r0 */
+ trampOnStack[1] = 0x4800000d; /* bl Lbase */
+ trampOnStack[2] = (uint32_t)realFunc;
+ trampOnStack[3] = (uint32_t)localsPtr;
+ trampOnStack[4] = 0x7d6802a6; /* Lbase: mflr r11 */
+ trampOnStack[5] = 0x818b0000; /* lwz r12,0(r11) */
+ trampOnStack[6] = 0x7c0803a6; /* mtlr r0 */
+ trampOnStack[7] = 0x7d8903a6; /* mtctr r12 */
+ trampOnStack[8] = 0x816b0004; /* lwz r11,4(r11) */
+ trampOnStack[9] = 0x4e800420; /* bctr */
+
+ /* clear instruction cache */
+ __clear_cache(trampOnStack, &trampOnStack[10]);
+}
+#endif /* __ppc__ */
diff --git a/contrib/compiler-rt/lib/truncdfsf2.c b/contrib/compiler-rt/lib/truncdfsf2.c
new file mode 100644
index 0000000..d289cb9
--- /dev/null
+++ b/contrib/compiler-rt/lib/truncdfsf2.c
@@ -0,0 +1,167 @@
+//===-- lib/truncdfsf2.c - double -> single conversion ------------*- C -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a fairly generic conversion from a wider to a narrower
+// IEEE-754 floating-point type in the default (round to nearest, ties to even)
+// rounding mode. The constants and types defined following the includes below
+// parameterize the conversion.
+//
+// This routine can be trivially adapted to support conversions to
+// half-precision or from quad-precision. It does not support types that don't
+// use the usual IEEE-754 interchange formats; specifically, some work would be
+// needed to adapt it to (for example) the Intel 80-bit format or PowerPC
+// double-double format.
+//
+// Note please, however, that this implementation is only intended to support
+// *narrowing* operations; if you need to convert to a *wider* floating-point
+// type (e.g. float -> double), then this routine will not do what you want it
+// to.
+//
+// It also requires that integer types at least as large as both formats
+// are available on the target platform; this may pose a problem when trying
+// to add support for quad on some 32-bit systems, for example.
+//
+// Finally, the following assumptions are made:
+//
+// 1. floating-point types and integer types have the same endianness on the
+// target platform
+//
+// 2. quiet NaNs, if supported, are indicated by the leading bit of the
+// significand field being set
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <limits.h>
+#include <stdbool.h>
+
+typedef double src_t;
+typedef uint64_t src_rep_t;
+#define SRC_REP_C UINT64_C
+static const int srcSigBits = 52;
+
+typedef float dst_t;
+typedef uint32_t dst_rep_t;
+#define DST_REP_C UINT32_C
+static const int dstSigBits = 23;
+
+// End of specialization parameters. Two helper routines for conversion to and
+// from the representation of floating-point data as integer values follow.
+
+static inline src_rep_t srcToRep(src_t x) {
+ const union { src_t f; src_rep_t i; } rep = {.f = x};
+ return rep.i;
+}
+
+static inline dst_t dstFromRep(dst_rep_t x) {
+ const union { dst_t f; dst_rep_t i; } rep = {.i = x};
+ return rep.f;
+}
+
+// End helper routines. Conversion implementation follows.
+
+dst_t __truncdfsf2(src_t a) {
+
+ // Various constants whose values follow from the type parameters.
+ // Any reasonable optimizer will fold and propagate all of these.
+ const int srcBits = sizeof(src_t)*CHAR_BIT;
+ const int srcExpBits = srcBits - srcSigBits - 1;
+ const int srcInfExp = (1 << srcExpBits) - 1;
+ const int srcExpBias = srcInfExp >> 1;
+
+ const src_rep_t srcMinNormal = SRC_REP_C(1) << srcSigBits;
+ const src_rep_t significandMask = srcMinNormal - 1;
+ const src_rep_t srcInfinity = (src_rep_t)srcInfExp << srcSigBits;
+ const src_rep_t srcSignMask = SRC_REP_C(1) << (srcSigBits + srcExpBits);
+ const src_rep_t srcAbsMask = srcSignMask - 1;
+ const src_rep_t roundMask = (SRC_REP_C(1) << (srcSigBits - dstSigBits)) - 1;
+ const src_rep_t halfway = SRC_REP_C(1) << (srcSigBits - dstSigBits - 1);
+
+ const int dstBits = sizeof(dst_t)*CHAR_BIT;
+ const int dstExpBits = dstBits - dstSigBits - 1;
+ const int dstInfExp = (1 << dstExpBits) - 1;
+ const int dstExpBias = dstInfExp >> 1;
+
+ const int underflowExponent = srcExpBias + 1 - dstExpBias;
+ const int overflowExponent = srcExpBias + dstInfExp - dstExpBias;
+ const src_rep_t underflow = (src_rep_t)underflowExponent << srcSigBits;
+ const src_rep_t overflow = (src_rep_t)overflowExponent << srcSigBits;
+
+ const dst_rep_t dstQNaN = DST_REP_C(1) << (dstSigBits - 1);
+ const dst_rep_t dstNaNCode = dstQNaN - 1;
+
+ // Break a into a sign and representation of the absolute value
+ const src_rep_t aRep = srcToRep(a);
+ const src_rep_t aAbs = aRep & srcAbsMask;
+ const src_rep_t sign = aRep & srcSignMask;
+ dst_rep_t absResult;
+
+ if (aAbs - underflow < aAbs - overflow) {
+ // The exponent of a is within the range of normal numbers in the
+ // destination format. We can convert by simply right-shifting with
+ // rounding and adjusting the exponent.
+ absResult = aAbs >> (srcSigBits - dstSigBits);
+ absResult -= (dst_rep_t)(srcExpBias - dstExpBias) << dstSigBits;
+
+ const src_rep_t roundBits = aAbs & roundMask;
+
+ // Round to nearest
+ if (roundBits > halfway)
+ absResult++;
+
+ // Ties to even
+ else if (roundBits == halfway)
+ absResult += absResult & 1;
+ }
+
+ else if (aAbs > srcInfinity) {
+ // a is NaN.
+ // Conjure the result by beginning with infinity, setting the qNaN
+ // bit and inserting the (truncated) trailing NaN field.
+ absResult = (dst_rep_t)dstInfExp << dstSigBits;
+ absResult |= dstQNaN;
+ absResult |= aAbs & dstNaNCode;
+ }
+
+ else if (aAbs > overflow) {
+ // a overflows to infinity.
+ absResult = (dst_rep_t)dstInfExp << dstSigBits;
+ }
+
+ else {
+ // a underflows on conversion to the destination type or is an exact
+ // zero. The result may be a denormal or zero. Extract the exponent
+ // to get the shift amount for the denormalization.
+ const int aExp = aAbs >> srcSigBits;
+ const int shift = srcExpBias - dstExpBias - aExp + 1;
+
+ const src_rep_t significand = (aRep & significandMask) | srcMinNormal;
+
+ // Right shift by the denormalization amount with sticky.
+ if (shift > srcSigBits) {
+ absResult = 0;
+ } else {
+ const bool sticky = significand << (srcBits - shift);
+ src_rep_t denormalizedSignificand = significand >> shift | sticky;
+ absResult = denormalizedSignificand >> (srcSigBits - dstSigBits);
+ const src_rep_t roundBits = denormalizedSignificand & roundMask;
+ // Round to nearest
+ if (roundBits > halfway)
+ absResult++;
+ // Ties to even
+ else if (roundBits == halfway)
+ absResult += absResult & 1;
+ }
+ }
+
+ // Apply the signbit to (dst_t)abs(a).
+ const dst_rep_t result = absResult | sign >> (srcBits - dstBits);
+ return dstFromRep(result);
+
+}
diff --git a/contrib/compiler-rt/lib/ucmpdi2.c b/contrib/compiler-rt/lib/ucmpdi2.c
new file mode 100644
index 0000000..d2900ca
--- /dev/null
+++ b/contrib/compiler-rt/lib/ucmpdi2.c
@@ -0,0 +1,38 @@
+/* ===-- ucmpdi2.c - Implement __ucmpdi2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ucmpdi2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: if (a < b) returns 0
+ * if (a == b) returns 1
+ * if (a > b) returns 2
+ */
+
+si_int
+__ucmpdi2(du_int a, du_int b)
+{
+ udwords x;
+ x.all = a;
+ udwords y;
+ y.all = b;
+ if (x.s.high < y.s.high)
+ return 0;
+ if (x.s.high > y.s.high)
+ return 2;
+ if (x.s.low < y.s.low)
+ return 0;
+ if (x.s.low > y.s.low)
+ return 2;
+ return 1;
+}
diff --git a/contrib/compiler-rt/lib/ucmpti2.c b/contrib/compiler-rt/lib/ucmpti2.c
new file mode 100644
index 0000000..0e7eea3
--- /dev/null
+++ b/contrib/compiler-rt/lib/ucmpti2.c
@@ -0,0 +1,42 @@
+/* ===-- ucmpti2.c - Implement __ucmpti2 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __ucmpti2 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Returns: if (a < b) returns 0
+ * if (a == b) returns 1
+ * if (a > b) returns 2
+ */
+
+si_int
+__ucmpti2(tu_int a, tu_int b)
+{
+ utwords x;
+ x.all = a;
+ utwords y;
+ y.all = b;
+ if (x.s.high < y.s.high)
+ return 0;
+ if (x.s.high > y.s.high)
+ return 2;
+ if (x.s.low < y.s.low)
+ return 0;
+ if (x.s.low > y.s.low)
+ return 2;
+ return 1;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/udivdi3.c b/contrib/compiler-rt/lib/udivdi3.c
new file mode 100644
index 0000000..25d1df6
--- /dev/null
+++ b/contrib/compiler-rt/lib/udivdi3.c
@@ -0,0 +1,25 @@
+/* ===-- udivdi3.c - Implement __udivdi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __udivdi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
+
+/* Returns: a / b */
+
+du_int
+__udivdi3(du_int a, du_int b)
+{
+ return __udivmoddi4(a, b, 0);
+}
diff --git a/contrib/compiler-rt/lib/udivmoddi4.c b/contrib/compiler-rt/lib/udivmoddi4.c
new file mode 100644
index 0000000..9274230
--- /dev/null
+++ b/contrib/compiler-rt/lib/udivmoddi4.c
@@ -0,0 +1,251 @@
+/* ===-- udivmoddi4.c - Implement __udivmoddi4 -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __udivmoddi4 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Effects: if rem != 0, *rem = a % b
+ * Returns: a / b
+ */
+
+/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
+
+du_int
+__udivmoddi4(du_int a, du_int b, du_int* rem)
+{
+ const unsigned n_uword_bits = sizeof(su_int) * CHAR_BIT;
+ const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT;
+ udwords n;
+ n.all = a;
+ udwords d;
+ d.all = b;
+ udwords q;
+ udwords r;
+ unsigned sr;
+ /* special cases, X is unknown, K != 0 */
+ if (n.s.high == 0)
+ {
+ if (d.s.high == 0)
+ {
+ /* 0 X
+ * ---
+ * 0 X
+ */
+ if (rem)
+ *rem = n.s.low % d.s.low;
+ return n.s.low / d.s.low;
+ }
+ /* 0 X
+ * ---
+ * K X
+ */
+ if (rem)
+ *rem = n.s.low;
+ return 0;
+ }
+ /* n.s.high != 0 */
+ if (d.s.low == 0)
+ {
+ if (d.s.high == 0)
+ {
+ /* K X
+ * ---
+ * 0 0
+ */
+ if (rem)
+ *rem = n.s.high % d.s.low;
+ return n.s.high / d.s.low;
+ }
+ /* d.s.high != 0 */
+ if (n.s.low == 0)
+ {
+ /* K 0
+ * ---
+ * K 0
+ */
+ if (rem)
+ {
+ r.s.high = n.s.high % d.s.high;
+ r.s.low = 0;
+ *rem = r.all;
+ }
+ return n.s.high / d.s.high;
+ }
+ /* K K
+ * ---
+ * K 0
+ */
+ if ((d.s.high & (d.s.high - 1)) == 0) /* if d is a power of 2 */
+ {
+ if (rem)
+ {
+ r.s.low = n.s.low;
+ r.s.high = n.s.high & (d.s.high - 1);
+ *rem = r.all;
+ }
+ return n.s.high >> __builtin_ctz(d.s.high);
+ }
+ /* K K
+ * ---
+ * K 0
+ */
+ sr = __builtin_clz(d.s.high) - __builtin_clz(n.s.high);
+ /* 0 <= sr <= n_uword_bits - 2 or sr large */
+ if (sr > n_uword_bits - 2)
+ {
+ if (rem)
+ *rem = n.all;
+ return 0;
+ }
+ ++sr;
+ /* 1 <= sr <= n_uword_bits - 1 */
+ /* q.all = n.all << (n_udword_bits - sr); */
+ q.s.low = 0;
+ q.s.high = n.s.low << (n_uword_bits - sr);
+ /* r.all = n.all >> sr; */
+ r.s.high = n.s.high >> sr;
+ r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr);
+ }
+ else /* d.s.low != 0 */
+ {
+ if (d.s.high == 0)
+ {
+ /* K X
+ * ---
+ * 0 K
+ */
+ if ((d.s.low & (d.s.low - 1)) == 0) /* if d is a power of 2 */
+ {
+ if (rem)
+ *rem = n.s.low & (d.s.low - 1);
+ if (d.s.low == 1)
+ return n.all;
+ unsigned sr = __builtin_ctz(d.s.low);
+ q.s.high = n.s.high >> sr;
+ q.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr);
+ return q.all;
+ }
+ /* K X
+ * ---
+ *0 K
+ */
+ sr = 1 + n_uword_bits + __builtin_clz(d.s.low) - __builtin_clz(n.s.high);
+ /* 2 <= sr <= n_udword_bits - 1
+ * q.all = n.all << (n_udword_bits - sr);
+ * r.all = n.all >> sr;
+ * if (sr == n_uword_bits)
+ * {
+ * q.s.low = 0;
+ * q.s.high = n.s.low;
+ * r.s.high = 0;
+ * r.s.low = n.s.high;
+ * }
+ * else if (sr < n_uword_bits) // 2 <= sr <= n_uword_bits - 1
+ * {
+ * q.s.low = 0;
+ * q.s.high = n.s.low << (n_uword_bits - sr);
+ * r.s.high = n.s.high >> sr;
+ * r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr);
+ * }
+ * else // n_uword_bits + 1 <= sr <= n_udword_bits - 1
+ * {
+ * q.s.low = n.s.low << (n_udword_bits - sr);
+ * q.s.high = (n.s.high << (n_udword_bits - sr)) |
+ * (n.s.low >> (sr - n_uword_bits));
+ * r.s.high = 0;
+ * r.s.low = n.s.high >> (sr - n_uword_bits);
+ * }
+ */
+ q.s.low = (n.s.low << (n_udword_bits - sr)) &
+ ((si_int)(n_uword_bits - sr) >> (n_uword_bits-1));
+ q.s.high = ((n.s.low << ( n_uword_bits - sr)) &
+ ((si_int)(sr - n_uword_bits - 1) >> (n_uword_bits-1))) |
+ (((n.s.high << (n_udword_bits - sr)) |
+ (n.s.low >> (sr - n_uword_bits))) &
+ ((si_int)(n_uword_bits - sr) >> (n_uword_bits-1)));
+ r.s.high = (n.s.high >> sr) &
+ ((si_int)(sr - n_uword_bits) >> (n_uword_bits-1));
+ r.s.low = ((n.s.high >> (sr - n_uword_bits)) &
+ ((si_int)(n_uword_bits - sr - 1) >> (n_uword_bits-1))) |
+ (((n.s.high << (n_uword_bits - sr)) |
+ (n.s.low >> sr)) &
+ ((si_int)(sr - n_uword_bits) >> (n_uword_bits-1)));
+ }
+ else
+ {
+ /* K X
+ * ---
+ * K K
+ */
+ sr = __builtin_clz(d.s.high) - __builtin_clz(n.s.high);
+ /* 0 <= sr <= n_uword_bits - 1 or sr large */
+ if (sr > n_uword_bits - 1)
+ {
+ if (rem)
+ *rem = n.all;
+ return 0;
+ }
+ ++sr;
+ /* 1 <= sr <= n_uword_bits */
+ /* q.all = n.all << (n_udword_bits - sr); */
+ q.s.low = 0;
+ q.s.high = n.s.low << (n_uword_bits - sr);
+ /* r.all = n.all >> sr;
+ * if (sr < n_uword_bits)
+ * {
+ * r.s.high = n.s.high >> sr;
+ * r.s.low = (n.s.high << (n_uword_bits - sr)) | (n.s.low >> sr);
+ * }
+ * else
+ * {
+ * r.s.high = 0;
+ * r.s.low = n.s.high;
+ * }
+ */
+ r.s.high = (n.s.high >> sr) &
+ ((si_int)(sr - n_uword_bits) >> (n_uword_bits-1));
+ r.s.low = (n.s.high << (n_uword_bits - sr)) |
+ ((n.s.low >> sr) &
+ ((si_int)(sr - n_uword_bits) >> (n_uword_bits-1)));
+ }
+ }
+ /* Not a special case
+ * q and r are initialized with:
+ * q.all = n.all << (n_udword_bits - sr);
+ * r.all = n.all >> sr;
+ * 1 <= sr <= n_udword_bits - 1
+ */
+ su_int carry = 0;
+ for (; sr > 0; --sr)
+ {
+ /* r:q = ((r:q) << 1) | carry */
+ r.s.high = (r.s.high << 1) | (r.s.low >> (n_uword_bits - 1));
+ r.s.low = (r.s.low << 1) | (q.s.high >> (n_uword_bits - 1));
+ q.s.high = (q.s.high << 1) | (q.s.low >> (n_uword_bits - 1));
+ q.s.low = (q.s.low << 1) | carry;
+ /* carry = 0;
+ * if (r.all >= d.all)
+ * {
+ * r.all -= d.all;
+ * carry = 1;
+ * }
+ */
+ const di_int s = (di_int)(d.all - r.all - 1) >> (n_udword_bits - 1);
+ carry = s & 1;
+ r.all -= d.all & s;
+ }
+ q.all = (q.all << 1) | carry;
+ if (rem)
+ *rem = r.all;
+ return q.all;
+}
diff --git a/contrib/compiler-rt/lib/udivmodti4.c b/contrib/compiler-rt/lib/udivmodti4.c
new file mode 100644
index 0000000..53b4072
--- /dev/null
+++ b/contrib/compiler-rt/lib/udivmodti4.c
@@ -0,0 +1,256 @@
+/* ===-- udivmodti4.c - Implement __udivmodti4 -----------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __udivmodti4 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+/* Effects: if rem != 0, *rem = a % b
+ * Returns: a / b
+ */
+
+/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
+
+tu_int
+__udivmodti4(tu_int a, tu_int b, tu_int* rem)
+{
+ const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT;
+ const unsigned n_utword_bits = sizeof(tu_int) * CHAR_BIT;
+ utwords n;
+ n.all = a;
+ utwords d;
+ d.all = b;
+ utwords q;
+ utwords r;
+ unsigned sr;
+ /* special cases, X is unknown, K != 0 */
+ if (n.s.high == 0)
+ {
+ if (d.s.high == 0)
+ {
+ /* 0 X
+ * ---
+ * 0 X
+ */
+ if (rem)
+ *rem = n.s.low % d.s.low;
+ return n.s.low / d.s.low;
+ }
+ /* 0 X
+ * ---
+ * K X
+ */
+ if (rem)
+ *rem = n.s.low;
+ return 0;
+ }
+ /* n.s.high != 0 */
+ if (d.s.low == 0)
+ {
+ if (d.s.high == 0)
+ {
+ /* K X
+ * ---
+ * 0 0
+ */
+ if (rem)
+ *rem = n.s.high % d.s.low;
+ return n.s.high / d.s.low;
+ }
+ /* d.s.high != 0 */
+ if (n.s.low == 0)
+ {
+ /* K 0
+ * ---
+ * K 0
+ */
+ if (rem)
+ {
+ r.s.high = n.s.high % d.s.high;
+ r.s.low = 0;
+ *rem = r.all;
+ }
+ return n.s.high / d.s.high;
+ }
+ /* K K
+ * ---
+ * K 0
+ */
+ if ((d.s.high & (d.s.high - 1)) == 0) /* if d is a power of 2 */
+ {
+ if (rem)
+ {
+ r.s.low = n.s.low;
+ r.s.high = n.s.high & (d.s.high - 1);
+ *rem = r.all;
+ }
+ return n.s.high >> __builtin_ctzll(d.s.high);
+ }
+ /* K K
+ * ---
+ * K 0
+ */
+ sr = __builtin_clzll(d.s.high) - __builtin_clzll(n.s.high);
+ /* 0 <= sr <= n_udword_bits - 2 or sr large */
+ if (sr > n_udword_bits - 2)
+ {
+ if (rem)
+ *rem = n.all;
+ return 0;
+ }
+ ++sr;
+ /* 1 <= sr <= n_udword_bits - 1 */
+ /* q.all = n.all << (n_utword_bits - sr); */
+ q.s.low = 0;
+ q.s.high = n.s.low << (n_udword_bits - sr);
+ /* r.all = n.all >> sr; */
+ r.s.high = n.s.high >> sr;
+ r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
+ }
+ else /* d.s.low != 0 */
+ {
+ if (d.s.high == 0)
+ {
+ /* K X
+ * ---
+ * 0 K
+ */
+ if ((d.s.low & (d.s.low - 1)) == 0) /* if d is a power of 2 */
+ {
+ if (rem)
+ *rem = n.s.low & (d.s.low - 1);
+ if (d.s.low == 1)
+ return n.all;
+ unsigned sr = __builtin_ctzll(d.s.low);
+ q.s.high = n.s.high >> sr;
+ q.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
+ return q.all;
+ }
+ /* K X
+ * ---
+ * 0 K
+ */
+ sr = 1 + n_udword_bits + __builtin_clzll(d.s.low)
+ - __builtin_clzll(n.s.high);
+ /* 2 <= sr <= n_utword_bits - 1
+ * q.all = n.all << (n_utword_bits - sr);
+ * r.all = n.all >> sr;
+ * if (sr == n_udword_bits)
+ * {
+ * q.s.low = 0;
+ * q.s.high = n.s.low;
+ * r.s.high = 0;
+ * r.s.low = n.s.high;
+ * }
+ * else if (sr < n_udword_bits) // 2 <= sr <= n_udword_bits - 1
+ * {
+ * q.s.low = 0;
+ * q.s.high = n.s.low << (n_udword_bits - sr);
+ * r.s.high = n.s.high >> sr;
+ * r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
+ * }
+ * else // n_udword_bits + 1 <= sr <= n_utword_bits - 1
+ * {
+ * q.s.low = n.s.low << (n_utword_bits - sr);
+ * q.s.high = (n.s.high << (n_utword_bits - sr)) |
+ * (n.s.low >> (sr - n_udword_bits));
+ * r.s.high = 0;
+ * r.s.low = n.s.high >> (sr - n_udword_bits);
+ * }
+ */
+ q.s.low = (n.s.low << (n_utword_bits - sr)) &
+ ((di_int)(int)(n_udword_bits - sr) >> (n_udword_bits-1));
+ q.s.high = ((n.s.low << ( n_udword_bits - sr)) &
+ ((di_int)(int)(sr - n_udword_bits - 1) >> (n_udword_bits-1))) |
+ (((n.s.high << (n_utword_bits - sr)) |
+ (n.s.low >> (sr - n_udword_bits))) &
+ ((di_int)(int)(n_udword_bits - sr) >> (n_udword_bits-1)));
+ r.s.high = (n.s.high >> sr) &
+ ((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1));
+ r.s.low = ((n.s.high >> (sr - n_udword_bits)) &
+ ((di_int)(int)(n_udword_bits - sr - 1) >> (n_udword_bits-1))) |
+ (((n.s.high << (n_udword_bits - sr)) |
+ (n.s.low >> sr)) &
+ ((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1)));
+ }
+ else
+ {
+ /* K X
+ * ---
+ * K K
+ */
+ sr = __builtin_clzll(d.s.high) - __builtin_clzll(n.s.high);
+ /*0 <= sr <= n_udword_bits - 1 or sr large */
+ if (sr > n_udword_bits - 1)
+ {
+ if (rem)
+ *rem = n.all;
+ return 0;
+ }
+ ++sr;
+ /* 1 <= sr <= n_udword_bits */
+ /* q.all = n.all << (n_utword_bits - sr); */
+ q.s.low = 0;
+ q.s.high = n.s.low << (n_udword_bits - sr);
+ /* r.all = n.all >> sr;
+ * if (sr < n_udword_bits)
+ * {
+ * r.s.high = n.s.high >> sr;
+ * r.s.low = (n.s.high << (n_udword_bits - sr)) | (n.s.low >> sr);
+ * }
+ * else
+ * {
+ * r.s.high = 0;
+ * r.s.low = n.s.high;
+ * }
+ */
+ r.s.high = (n.s.high >> sr) &
+ ((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1));
+ r.s.low = (n.s.high << (n_udword_bits - sr)) |
+ ((n.s.low >> sr) &
+ ((di_int)(int)(sr - n_udword_bits) >> (n_udword_bits-1)));
+ }
+ }
+ /* Not a special case
+ * q and r are initialized with:
+ * q.all = n.all << (n_utword_bits - sr);
+ * r.all = n.all >> sr;
+ * 1 <= sr <= n_utword_bits - 1
+ */
+ su_int carry = 0;
+ for (; sr > 0; --sr)
+ {
+ /* r:q = ((r:q) << 1) | carry */
+ r.s.high = (r.s.high << 1) | (r.s.low >> (n_udword_bits - 1));
+ r.s.low = (r.s.low << 1) | (q.s.high >> (n_udword_bits - 1));
+ q.s.high = (q.s.high << 1) | (q.s.low >> (n_udword_bits - 1));
+ q.s.low = (q.s.low << 1) | carry;
+ /* carry = 0;
+ * if (r.all >= d.all)
+ * {
+ * r.all -= d.all;
+ * carry = 1;
+ * }
+ */
+ const ti_int s = (ti_int)(d.all - r.all - 1) >> (n_utword_bits - 1);
+ carry = s & 1;
+ r.all -= d.all & s;
+ }
+ q.all = (q.all << 1) | carry;
+ if (rem)
+ *rem = r.all;
+ return q.all;
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/udivsi3.c b/contrib/compiler-rt/lib/udivsi3.c
new file mode 100644
index 0000000..70528b6
--- /dev/null
+++ b/contrib/compiler-rt/lib/udivsi3.c
@@ -0,0 +1,63 @@
+/* ===-- udivsi3.c - Implement __udivsi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __udivsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a / b */
+
+/* Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide */
+
+su_int
+__udivsi3(su_int n, su_int d)
+{
+ const unsigned n_uword_bits = sizeof(su_int) * CHAR_BIT;
+ su_int q;
+ su_int r;
+ unsigned sr;
+ /* special cases */
+ if (d == 0)
+ return 0; /* ?! */
+ if (n == 0)
+ return 0;
+ sr = __builtin_clz(d) - __builtin_clz(n);
+ /* 0 <= sr <= n_uword_bits - 1 or sr large */
+ if (sr > n_uword_bits - 1) /* d > r */
+ return 0;
+ if (sr == n_uword_bits - 1) /* d == 1 */
+ return n;
+ ++sr;
+ /* 1 <= sr <= n_uword_bits - 1 */
+ /* Not a special case */
+ q = n << (n_uword_bits - sr);
+ r = n >> sr;
+ su_int carry = 0;
+ for (; sr > 0; --sr)
+ {
+ /* r:q = ((r:q) << 1) | carry */
+ r = (r << 1) | (q >> (n_uword_bits - 1));
+ q = (q << 1) | carry;
+ /* carry = 0;
+ * if (r.all >= d.all)
+ * {
+ * r.all -= d.all;
+ * carry = 1;
+ * }
+ */
+ const si_int s = (si_int)(d - r - 1) >> (n_uword_bits - 1);
+ carry = s & 1;
+ r -= d & s;
+ }
+ q = (q << 1) | carry;
+ return q;
+}
diff --git a/contrib/compiler-rt/lib/udivti3.c b/contrib/compiler-rt/lib/udivti3.c
new file mode 100644
index 0000000..fb810fd
--- /dev/null
+++ b/contrib/compiler-rt/lib/udivti3.c
@@ -0,0 +1,29 @@
+/* ===-- udivti3.c - Implement __udivti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __udivti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
+
+/* Returns: a / b */
+
+tu_int
+__udivti3(tu_int a, tu_int b)
+{
+ return __udivmodti4(a, b, 0);
+}
+
+#endif /* __x86_64 */
diff --git a/contrib/compiler-rt/lib/umoddi3.c b/contrib/compiler-rt/lib/umoddi3.c
new file mode 100644
index 0000000..807bb5ce
--- /dev/null
+++ b/contrib/compiler-rt/lib/umoddi3.c
@@ -0,0 +1,27 @@
+/* ===-- umoddi3.c - Implement __umoddi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __umoddi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
+
+/* Returns: a % b */
+
+du_int
+__umoddi3(du_int a, du_int b)
+{
+ du_int r;
+ __udivmoddi4(a, b, &r);
+ return r;
+}
diff --git a/contrib/compiler-rt/lib/umodsi3.c b/contrib/compiler-rt/lib/umodsi3.c
new file mode 100644
index 0000000..ead7737
--- /dev/null
+++ b/contrib/compiler-rt/lib/umodsi3.c
@@ -0,0 +1,25 @@
+/* ===-- umodsi3.c - Implement __umodsi3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __umodsi3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#include "int_lib.h"
+
+/* Returns: a % b */
+
+su_int __udivsi3(su_int a, su_int b);
+
+su_int
+__umodsi3(su_int a, su_int b)
+{
+ return a - __udivsi3(a, b) * b;
+}
diff --git a/contrib/compiler-rt/lib/umodti3.c b/contrib/compiler-rt/lib/umodti3.c
new file mode 100644
index 0000000..6c8a758
--- /dev/null
+++ b/contrib/compiler-rt/lib/umodti3.c
@@ -0,0 +1,31 @@
+/* ===-- umodti3.c - Implement __umodti3 -----------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ *
+ * ===----------------------------------------------------------------------===
+ *
+ * This file implements __umodti3 for the compiler_rt library.
+ *
+ * ===----------------------------------------------------------------------===
+ */
+
+#if __x86_64
+
+#include "int_lib.h"
+
+tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
+
+/* Returns: a % b */
+
+tu_int
+__umodti3(tu_int a, tu_int b)
+{
+ tu_int r;
+ __udivmodti4(a, b, &r);
+ return r;
+}
+
+#endif
diff --git a/contrib/compiler-rt/lib/x86_64/floatdidf.c b/contrib/compiler-rt/lib/x86_64/floatdidf.c
new file mode 100644
index 0000000..cce3cd5
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatdidf.c
@@ -0,0 +1,16 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* double __floatdidf(di_int a); */
+
+#ifdef __x86_64__
+
+#include <stdint.h>
+
+double __floatdidf(int64_t a)
+{
+ return (double)a;
+}
+
+#endif /* __x86_64__ */
diff --git a/contrib/compiler-rt/lib/x86_64/floatdisf.c b/contrib/compiler-rt/lib/x86_64/floatdisf.c
new file mode 100644
index 0000000..753ba90
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatdisf.c
@@ -0,0 +1,14 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+#ifdef __x86_64__
+
+#include <stdint.h>
+
+float __floatdisf(int64_t a)
+{
+ return (float)a;
+}
+
+#endif /* __x86_64__ */
diff --git a/contrib/compiler-rt/lib/x86_64/floatdixf.c b/contrib/compiler-rt/lib/x86_64/floatdixf.c
new file mode 100644
index 0000000..569f727
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatdixf.c
@@ -0,0 +1,16 @@
+/* This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
+ */
+
+/* long double __floatdixf(di_int a); */
+
+#ifdef __x86_64__
+
+#include <stdint.h>
+
+long double __floatdixf(int64_t a)
+{
+ return (long double)a;
+}
+
+#endif /* __i386__ */
diff --git a/contrib/compiler-rt/lib/x86_64/floatundidf.S b/contrib/compiler-rt/lib/x86_64/floatundidf.S
new file mode 100644
index 0000000..6e684b2
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatundidf.S
@@ -0,0 +1,43 @@
+//===-- floatundidf.S - Implement __floatundidf for x86_64 ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements __floatundidf for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../assembly.h"
+
+// double __floatundidf(du_int a);
+
+#ifdef __x86_64__
+
+#ifndef __ELF__
+.const
+#endif
+.align 4
+twop52: .quad 0x4330000000000000
+twop84_plus_twop52:
+ .quad 0x4530000000100000
+twop84: .quad 0x4530000000000000
+
+#define REL_ADDR(_a) (_a)(%rip)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundidf)
+ movd %edi, %xmm0 // low 32 bits of a
+ shrq $32, %rdi // high 32 bits of a
+ orq REL_ADDR(twop84), %rdi // 0x1p84 + a_hi (no rounding occurs)
+ orpd REL_ADDR(twop52), %xmm0 // 0x1p52 + a_lo (no rounding occurs)
+ movd %rdi, %xmm1
+ subsd REL_ADDR(twop84_plus_twop52), %xmm1 // a_hi - 0x1p52 (no rounding occurs)
+ addsd %xmm1, %xmm0 // a_hi + a_lo (round happens here)
+ ret
+
+#endif // __x86_64__
diff --git a/contrib/compiler-rt/lib/x86_64/floatundisf.S b/contrib/compiler-rt/lib/x86_64/floatundisf.S
new file mode 100644
index 0000000..fe20963
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatundisf.S
@@ -0,0 +1,33 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// float __floatundisf(du_int a);
+
+#ifdef __x86_64__
+
+#ifndef __ELF__
+.literal4
+#endif
+two: .single 2.0
+
+#define REL_ADDR(_a) (_a)(%rip)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundisf)
+ movq $1, %rsi
+ testq %rdi, %rdi
+ js 1f
+ cvtsi2ssq %rdi, %xmm0
+ ret
+
+1: andq %rdi, %rsi
+ shrq %rdi
+ orq %rsi, %rdi
+ cvtsi2ssq %rdi, %xmm0
+ mulss REL_ADDR(two), %xmm0
+ ret
+
+#endif // __x86_64__
diff --git a/contrib/compiler-rt/lib/x86_64/floatundixf.S b/contrib/compiler-rt/lib/x86_64/floatundixf.S
new file mode 100644
index 0000000..246f026
--- /dev/null
+++ b/contrib/compiler-rt/lib/x86_64/floatundixf.S
@@ -0,0 +1,62 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+#include "../assembly.h"
+
+// long double __floatundixf(du_int a);
+
+#ifdef __x86_64__
+
+#ifndef __ELF__
+.const
+#endif
+.align 4
+twop64: .quad 0x43f0000000000000
+
+#define REL_ADDR(_a) (_a)(%rip)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundixf)
+ movq %rdi, -8(%rsp)
+ fildq -8(%rsp)
+ test %rdi, %rdi
+ js 1f
+ ret
+1: faddl REL_ADDR(twop64)
+ ret
+
+#endif // __x86_64__
+
+
+/* Branch-free implementation is ever so slightly slower, but more beautiful.
+ It is likely superior for inlining, so I kept it around for future reference.
+
+#ifdef __x86_64__
+
+.const
+.align 4
+twop52: .quad 0x4330000000000000
+twop84_plus_twop52_neg:
+ .quad 0xc530000000100000
+twop84: .quad 0x4530000000000000
+
+#define REL_ADDR(_a) (_a)(%rip)
+
+.text
+.align 4
+DEFINE_COMPILERRT_FUNCTION(__floatundixf)
+ movl %edi, %esi // low 32 bits of input
+ shrq $32, %rdi // hi 32 bits of input
+ orq REL_ADDR(twop84), %rdi // 2^84 + hi (as a double)
+ orq REL_ADDR(twop52), %rsi // 2^52 + lo (as a double)
+ movq %rdi, -8(%rsp)
+ movq %rsi, -16(%rsp)
+ fldl REL_ADDR(twop84_plus_twop52_neg)
+ faddl -8(%rsp) // hi - 2^52 (as double extended, no rounding occurs)
+ faddl -16(%rsp) // hi + lo (as double extended)
+ ret
+
+#endif // __x86_64__
+
+*/
diff --git a/contrib/gdb/gdb/mips-tdep.c b/contrib/gdb/gdb/mips-tdep.c
index cd37764..d4a4c73 100644
--- a/contrib/gdb/gdb/mips-tdep.c
+++ b/contrib/gdb/gdb/mips-tdep.c
@@ -1495,6 +1495,7 @@ mips_mdebug_frame_cache (struct frame_info *next_frame, void **this_cache)
int kernel_trap;
/* What registers have been saved? Bitmasks. */
unsigned long gen_mask, float_mask;
+ long reg_offset;
if ((*this_cache) != NULL)
return (*this_cache);
@@ -1513,6 +1514,8 @@ mips_mdebug_frame_cache (struct frame_info *next_frame, void **this_cache)
/* Extract the frame's base. */
cache->base = (frame_unwind_register_signed (next_frame, NUM_REGS + PROC_FRAME_REG (proc_desc))
+ PROC_FRAME_OFFSET (proc_desc) - PROC_FRAME_ADJUST (proc_desc));
+ /* Save registers offset from scratching by following find_proc_desc call */
+ reg_offset = PROC_REG_OFFSET (proc_desc);
kernel_trap = PROC_REG_MASK (proc_desc) & 1;
gen_mask = kernel_trap ? 0xFFFFFFFF : PROC_REG_MASK (proc_desc);
@@ -1567,8 +1570,7 @@ mips_mdebug_frame_cache (struct frame_info *next_frame, void **this_cache)
/* Fill in the offsets for the registers which gen_mask says were
saved. */
{
- CORE_ADDR reg_position = (cache->base
- + PROC_REG_OFFSET (proc_desc));
+ CORE_ADDR reg_position = (cache->base + reg_offset);
int ireg;
for (ireg = MIPS_NUMREGS - 1; gen_mask; --ireg, gen_mask <<= 1)
if (gen_mask & 0x80000000)
@@ -2162,15 +2164,18 @@ restart:
{
PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
set_reg_offset (temp_saved_regs, reg, sp + low_word);
+ /* Do we have registers offset yet? */
+ if (!PROC_REG_OFFSET (&temp_proc_desc))
+ PROC_REG_OFFSET (&temp_proc_desc) = low_word - PROC_FRAME_OFFSET (&temp_proc_desc);
}
else if ((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
{
- /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra,
- but the register size used is only 32 bits. Make the address
- for the saved register point to the lower 32 bits. */
PROC_REG_MASK (&temp_proc_desc) |= 1 << reg;
set_reg_offset (temp_saved_regs, reg,
- sp + low_word + 8 - mips_regsize (current_gdbarch));
+ sp + low_word);
+ /* Do we have registers offset yet? */
+ if (!PROC_REG_OFFSET (&temp_proc_desc))
+ PROC_REG_OFFSET (&temp_proc_desc) = low_word - PROC_FRAME_OFFSET (&temp_proc_desc);
}
else if (high_word == 0x27be) /* addiu $30,$sp,size */
{
diff --git a/contrib/gdb/gdb/mips-tdep.h b/contrib/gdb/gdb/mips-tdep.h
index af9a3c8..5c78591 100644
--- a/contrib/gdb/gdb/mips-tdep.h
+++ b/contrib/gdb/gdb/mips-tdep.h
@@ -78,7 +78,7 @@ enum {
MIPS_EMBED_BADVADDR_REGNUM = 35,
MIPS_EMBED_CAUSE_REGNUM = 36,
MIPS_EMBED_PC_REGNUM = 37,
- MIPS_EMBED_FP0_REGNUM = 38
+ MIPS_EMBED_FP0_REGNUM = 40
};
/* Defined in mips-tdep.c and used in remote-mips.c */
diff --git a/contrib/gdb/gdb/mipsfbsd-tdep.h b/contrib/gdb/gdb/mipsfbsd-tdep.h
index 6b00bb4..2ac3d70 100644
--- a/contrib/gdb/gdb/mipsfbsd-tdep.h
+++ b/contrib/gdb/gdb/mipsfbsd-tdep.h
@@ -34,7 +34,7 @@ void mipsfbsd_fill_reg (char *, int);
void mipsfbsd_supply_fpreg (char *, int);
void mipsfbsd_fill_fpreg (char *, int);
-#define SIZEOF_STRUCT_REG (38 * mips_regsize (current_gdbarch))
-#define SIZEOF_STRUCT_FPREG (33 * mips_regsize (current_gdbarch))
+#define SIZEOF_STRUCT_REG (40 * mips_regsize (current_gdbarch))
+#define SIZEOF_STRUCT_FPREG (34 * mips_regsize (current_gdbarch))
#endif /* mipsfbsd_TDEP_H */
diff --git a/crypto/openssh/ChangeLog b/crypto/openssh/ChangeLog
index a08e1a7..6a3f64a 100644
--- a/crypto/openssh/ChangeLog
+++ b/crypto/openssh/ChangeLog
@@ -1,3 +1,522 @@
+20100823
+ - (djm) Release OpenSSH-5.6p1
+
+20100816
+ - (dtucker) [configure.ac openbsd-compat/Makefile.in
+ openbsd-compat/openbsd-compat.h openbsd-compat/strptime.c] Add strptime to
+ the compat library which helps on platforms like old IRIX. Based on work
+ by djm, tested by Tom Christensen.
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/08/12 21:49:44
+ [ssh.c]
+ close any extra file descriptors inherited from parent at start and
+ reopen stdin/stdout to /dev/null when forking for ControlPersist.
+
+ prevents tools that fork and run a captive ssh for communication from
+ failing to exit when the ssh completes while they wait for these fds to
+ close. The inherited fds may persist arbitrarily long if a background
+ mux master has been started by ControlPersist. cvs and scp were effected
+ by this.
+
+ "please commit" markus@
+ - (djm) [regress/README.regress] typo
+
+20100812
+ - (tim) [regress/login-timeout.sh regress/reconfigure.sh regress/reexec.sh
+ regress/test-exec.sh] Under certain conditions when testing with sudo
+ tests would fail because the pidfile could not be read by a regular user.
+ "cat: cannot open ...../regress/pidfile: Permission denied (error 13)"
+ Make sure cat is run by $SUDO. no objection from me. djm@
+ - (tim) [auth.c] add cast to quiet compiler. Change only affects SVR5 systems.
+
+20100809
+ - (djm) bz#1561: don't bother setting IFF_UP on tun(4) device if it is
+ already set. Makes FreeBSD user openable tunnels useful; patch from
+ richard.burakowski+ossh AT mrburak.net, ok dtucker@
+ - (dtucker) bug #1530: strip trailing ":" from hostname in ssh-copy-id.
+ based in part on a patch from Colin Watson, ok djm@
+
+20100809
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/08/08 16:26:42
+ [version.h]
+ crank to 5.6
+ - (djm) [README contrib/caldera/openssh.spec contrib/redhat/openssh.spec]
+ [contrib/suse/openssh.spec] Crank version numbers
+
+20100805
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/08/04 05:37:01
+ [ssh.1 ssh_config.5 sshd.8]
+ Remove mentions of weird "addr/port" alternate address format for IPv6
+ addresses combinations. It hasn't worked for ages and we have supported
+ the more commen "[addr]:port" format for a long time. ok jmc@ markus@
+ - djm@cvs.openbsd.org 2010/08/04 05:40:39
+ [PROTOCOL.certkeys ssh-keygen.c]
+ tighten the rules for certificate encoding by requiring that options
+ appear in lexical order and make our ssh-keygen comply. ok markus@
+ - djm@cvs.openbsd.org 2010/08/04 05:42:47
+ [auth.c auth2-hostbased.c authfile.c authfile.h ssh-keysign.8]
+ [ssh-keysign.c ssh.c]
+ enable certificates for hostbased authentication, from Iain Morgan;
+ "looks ok" markus@
+ - djm@cvs.openbsd.org 2010/08/04 05:49:22
+ [authfile.c]
+ commited the wrong version of the hostbased certificate diff; this
+ version replaces some strlc{py,at} verbosity with xasprintf() at
+ the request of markus@
+ - djm@cvs.openbsd.org 2010/08/04 06:07:11
+ [ssh-keygen.1 ssh-keygen.c]
+ Support CA keys in PKCS#11 tokens; feedback and ok markus@
+ - djm@cvs.openbsd.org 2010/08/04 06:08:40
+ [ssh-keysign.c]
+ clean for -Wuninitialized (Id sync only; portable had this change)
+ - djm@cvs.openbsd.org 2010/08/05 13:08:42
+ [channels.c]
+ Fix a trio of bugs in the local/remote window calculation for datagram
+ data channels (i.e. TunnelForward):
+
+ Calculate local_consumed correctly in channel_handle_wfd() by measuring
+ the delta to buffer_len(c->output) from when we start to when we finish.
+ The proximal problem here is that the output_filter we use in portable
+ modified the length of the dequeued datagram (to futz with the headers
+ for !OpenBSD).
+
+ In channel_output_poll(), don't enqueue datagrams that won't fit in the
+ peer's advertised packet size (highly unlikely to ever occur) or which
+ won't fit in the peer's remaining window (more likely).
+
+ In channel_input_data(), account for the 4-byte string header in
+ datagram packets that we accept from the peer and enqueue in c->output.
+
+ report, analysis and testing 2/3 cases from wierbows AT us.ibm.com;
+ "looks good" markus@
+
+20100803
+ - (dtucker) [monitor.c] Bug #1795: Initialize the values to be returned from
+ PAM to sane values in case the PAM method doesn't write to them. Spotted by
+ Bitman Zhou, ok djm@.
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/07/16 04:45:30
+ [ssh-keygen.c]
+ avoid bogus compiler warning
+ - djm@cvs.openbsd.org 2010/07/16 14:07:35
+ [ssh-rsa.c]
+ more timing paranoia - compare all parts of the expected decrypted
+ data before returning. AFAIK not exploitable in the SSH protocol.
+ "groovy" deraadt@
+ - djm@cvs.openbsd.org 2010/07/19 03:16:33
+ [sftp-client.c]
+ bz#1797: fix swapped args in upload_dir_internal(), breaking recursive
+ upload depth checks and causing verbose printing of transfers to always
+ be turned on; patch from imorgan AT nas.nasa.gov
+ - djm@cvs.openbsd.org 2010/07/19 09:15:12
+ [clientloop.c readconf.c readconf.h ssh.c ssh_config.5]
+ add a "ControlPersist" option that automatically starts a background
+ ssh(1) multiplex master when connecting. This connection can stay alive
+ indefinitely, or can be set to automatically close after a user-specified
+ duration of inactivity. bz#1330 - patch by dwmw2 AT infradead.org, but
+ further hacked on by wmertens AT cisco.com, apb AT cequrux.com,
+ martin-mindrot-bugzilla AT earth.li and myself; "looks ok" markus@
+ - djm@cvs.openbsd.org 2010/07/21 02:10:58
+ [misc.c]
+ sync timingsafe_bcmp() with the one dempsky@ committed to sys/lib/libkern
+ - dtucker@cvs.openbsd.org 2010/07/23 08:49:25
+ [ssh.1]
+ Ciphers is documented in ssh_config(5) these days
+
+20100819
+ - (dtucker) [contrib/ssh-copy-ud.1] Bug #1786: update ssh-copy-id.1 with more
+ details about its behaviour WRT existing directories. Patch from
+ asguthrie at gmail com, ok djm.
+
+20100716
+ - (djm) OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/07/02 04:32:44
+ [misc.c]
+ unbreak strdelim() skipping past quoted strings, e.g.
+ AllowUsers "blah blah" blah
+ was broken; report and fix in bz#1757 from bitman.zhou AT centrify.com
+ ok dtucker;
+ - djm@cvs.openbsd.org 2010/07/12 22:38:52
+ [ssh.c]
+ Make ExitOnForwardFailure work with fork-after-authentication ("ssh -f")
+ for protocol 2. ok markus@
+ - djm@cvs.openbsd.org 2010/07/12 22:41:13
+ [ssh.c ssh_config.5]
+ expand %h to the hostname in ssh_config Hostname options. While this
+ sounds useless, it is actually handy for working with unqualified
+ hostnames:
+
+ Host *.*
+ Hostname %h
+ Host *
+ Hostname %h.example.org
+
+ "I like it" markus@
+ - djm@cvs.openbsd.org 2010/07/13 11:52:06
+ [auth-rsa.c channels.c jpake.c key.c misc.c misc.h monitor.c]
+ [packet.c ssh-rsa.c]
+ implement a timing_safe_cmp() function to compare memory without leaking
+ timing information by short-circuiting like memcmp() and use it for
+ some of the more sensitive comparisons (though nothing high-value was
+ readily attackable anyway); "looks ok" markus@
+ - djm@cvs.openbsd.org 2010/07/13 23:13:16
+ [auth-rsa.c channels.c jpake.c key.c misc.c misc.h monitor.c packet.c]
+ [ssh-rsa.c]
+ s/timing_safe_cmp/timingsafe_bcmp/g
+ - jmc@cvs.openbsd.org 2010/07/14 17:06:58
+ [ssh.1]
+ finally ssh synopsis looks nice again! this commit just removes a ton of
+ hacks we had in place to make it work with old groff;
+ - schwarze@cvs.openbsd.org 2010/07/15 21:20:38
+ [ssh-keygen.1]
+ repair incorrect block nesting, which screwed up indentation;
+ problem reported and fix OK by jmc@
+
+20100714
+ - (tim) [contrib/redhat/openssh.spec] Bug 1796: Test for skip_x11_askpass
+ (line 77) should have been for no_x11_askpass.
+
+20100702
+ - (djm) OpenBSD CVS Sync
+ - jmc@cvs.openbsd.org 2010/06/26 00:57:07
+ [ssh_config.5]
+ tweak previous;
+ - djm@cvs.openbsd.org 2010/06/26 23:04:04
+ [ssh.c]
+ oops, forgot to #include <canohost.h>; spotted and patch from chl@
+ - djm@cvs.openbsd.org 2010/06/29 23:15:30
+ [ssh-keygen.1 ssh-keygen.c]
+ allow import (-i) and export (-e) of PEM and PKCS#8 encoded keys;
+ bz#1749; ok markus@
+ - djm@cvs.openbsd.org 2010/06/29 23:16:46
+ [auth2-pubkey.c sshd_config.5]
+ allow key options (command="..." and friends) in AuthorizedPrincipals;
+ ok markus@
+ - jmc@cvs.openbsd.org 2010/06/30 07:24:25
+ [ssh-keygen.1]
+ tweak previous;
+ - jmc@cvs.openbsd.org 2010/06/30 07:26:03
+ [ssh-keygen.c]
+ sort usage();
+ - jmc@cvs.openbsd.org 2010/06/30 07:28:34
+ [sshd_config.5]
+ tweak previous;
+ - millert@cvs.openbsd.org 2010/07/01 13:06:59
+ [scp.c]
+ Fix a longstanding problem where if you suspend scp at the
+ password/passphrase prompt the terminal mode is not restored.
+ OK djm@
+ - phessler@cvs.openbsd.org 2010/06/27 19:19:56
+ [regress/Makefile]
+ fix how we run the tests so we can successfully use SUDO='sudo -E'
+ in our env
+ - djm@cvs.openbsd.org 2010/06/29 23:59:54
+ [cert-userkey.sh]
+ regress tests for key options in AuthorizedPrincipals
+
+20100627
+ - (tim) [openbsd-compat/port-uw.c] Reorder includes. auth-options.h now needs
+ key.h.
+
+20100626
+ - (djm) OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/05/21 05:00:36
+ [misc.c]
+ colon() returns char*, so s/return (0)/return NULL/
+ - markus@cvs.openbsd.org 2010/06/08 21:32:19
+ [ssh-pkcs11.c]
+ check length of value returned C_GetAttributValue for != 0
+ from mdrtbugzilla@codefive.co.uk; bugzilla #1773; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/17 07:07:30
+ [mux.c]
+ Correct sizing of object to be allocated by calloc(), replacing
+ sizeof(state) with sizeof(*state). This worked by accident since
+ the struct contained a single int at present, but could have broken
+ in the future. patch from hyc AT symas.com
+ - djm@cvs.openbsd.org 2010/06/18 00:58:39
+ [sftp.c]
+ unbreak ls in working directories that contains globbing characters in
+ their pathnames. bz#1655 reported by vgiffin AT apple.com
+ - djm@cvs.openbsd.org 2010/06/18 03:16:03
+ [session.c]
+ Missing check for chroot_director == "none" (we already checked against
+ NULL); bz#1564 from Jan.Pechanec AT Sun.COM
+ - djm@cvs.openbsd.org 2010/06/18 04:43:08
+ [sftp-client.c]
+ fix memory leak in do_realpath() error path; bz#1771, patch from
+ anicka AT suse.cz
+ - djm@cvs.openbsd.org 2010/06/22 04:22:59
+ [servconf.c sshd_config.5]
+ expose some more sshd_config options inside Match blocks:
+ AuthorizedKeysFile AuthorizedPrincipalsFile
+ HostbasedUsesNameFromPacketOnly PermitTunnel
+ bz#1764; feedback from imorgan AT nas.nasa.gov; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/22 04:32:06
+ [ssh-keygen.c]
+ standardise error messages when attempting to open private key
+ files to include "progname: filename: error reason"
+ bz#1783; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/22 04:49:47
+ [auth.c]
+ queue auth debug messages for bad ownership or permissions on the user's
+ keyfiles. These messages will be sent after the user has successfully
+ authenticated (where our client will display them with LogLevel=debug).
+ bz#1554; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/22 04:54:30
+ [ssh-keyscan.c]
+ replace verbose and overflow-prone Linebuf code with read_keyfile_line()
+ based on patch from joachim AT joachimschipper.nl; bz#1565; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/22 04:59:12
+ [session.c]
+ include the user name on "subsystem request for ..." log messages;
+ bz#1571; ok dtucker@
+ - djm@cvs.openbsd.org 2010/06/23 02:59:02
+ [ssh-keygen.c]
+ fix printing of extensions in v01 certificates that I broke in r1.190
+ - djm@cvs.openbsd.org 2010/06/25 07:14:46
+ [channels.c mux.c readconf.c readconf.h ssh.h]
+ bz#1327: remove hardcoded limit of 100 permitopen clauses and port
+ forwards per direction; ok markus@ stevesk@
+ - djm@cvs.openbsd.org 2010/06/25 07:20:04
+ [channels.c session.c]
+ bz#1750: fix requirement for /dev/null inside ChrootDirectory for
+ internal-sftp accidentally introduced in r1.253 by removing the code
+ that opens and dup /dev/null to stderr and modifying the channels code
+ to read stderr but discard it instead; ok markus@
+ - djm@cvs.openbsd.org 2010/06/25 08:46:17
+ [auth1.c auth2-none.c]
+ skip the initial check for access with an empty password when
+ PermitEmptyPasswords=no; bz#1638; ok markus@
+ - djm@cvs.openbsd.org 2010/06/25 23:10:30
+ [ssh.c]
+ log the hostname and address that we connected to at LogLevel=verbose
+ after authentication is successful to mitigate "phishing" attacks by
+ servers with trusted keys that accept authentication silently and
+ automatically before presenting fake password/passphrase prompts;
+ "nice!" markus@
+ - djm@cvs.openbsd.org 2010/06/25 23:10:30
+ [ssh.c]
+ log the hostname and address that we connected to at LogLevel=verbose
+ after authentication is successful to mitigate "phishing" attacks by
+ servers with trusted keys that accept authentication silently and
+ automatically before presenting fake password/passphrase prompts;
+ "nice!" markus@
+
+20100622
+ - (djm) [loginrec.c] crank LINFO_NAMESIZE (username length) to 512
+ bz#1579; ok dtucker
+
+20100618
+ - (djm) [contrib/ssh-copy-id] Update key file explicitly under ~
+ rather than assuming that $CWD == $HOME. bz#1500, patch from
+ timothy AT gelter.com
+
+20100617
+ - (tim) [contrib/cygwin/README] Remove a reference to the obsolete
+ minires-devel package, and to add the reference to the libedit-devel
+ package since CYgwin now provides libedit. Patch from Corinna Vinschen.
+
+20100521
+ - (djm) OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/05/07 11:31:26
+ [regress/Makefile regress/cert-userkey.sh]
+ regress tests for AuthorizedPrincipalsFile and "principals=" key option.
+ feedback and ok markus@
+ - djm@cvs.openbsd.org 2010/05/11 02:58:04
+ [auth-rsa.c]
+ don't accept certificates marked as "cert-authority" here; ok markus@
+ - djm@cvs.openbsd.org 2010/05/14 00:47:22
+ [ssh-add.c]
+ check that the certificate matches the corresponding private key before
+ grafting it on
+ - djm@cvs.openbsd.org 2010/05/14 23:29:23
+ [channels.c channels.h mux.c ssh.c]
+ Pause the mux channel while waiting for reply from aynch callbacks.
+ Prevents misordering of replies if new requests arrive while waiting.
+
+ Extend channel open confirm callback to allow signalling failure
+ conditions as well as success. Use this to 1) fix a memory leak, 2)
+ start using the above pause mechanism and 3) delay sending a success/
+ failure message on mux slave session open until we receive a reply from
+ the server.
+
+ motivated by and with feedback from markus@
+ - markus@cvs.openbsd.org 2010/05/16 12:55:51
+ [PROTOCOL.mux clientloop.h mux.c readconf.c readconf.h ssh.1 ssh.c]
+ mux support for remote forwarding with dynamic port allocation,
+ use with
+ LPORT=`ssh -S muxsocket -R0:localhost:25 -O forward somehost`
+ feedback and ok djm@
+ - djm@cvs.openbsd.org 2010/05/20 11:25:26
+ [auth2-pubkey.c]
+ fix logspam when key options (from="..." especially) deny non-matching
+ keys; reported by henning@ also bz#1765; ok markus@ dtucker@
+ - djm@cvs.openbsd.org 2010/05/20 23:46:02
+ [PROTOCOL.certkeys auth-options.c ssh-keygen.c]
+ Move the permit-* options to the non-critical "extensions" field for v01
+ certificates. The logic is that if another implementation fails to
+ implement them then the connection just loses features rather than fails
+ outright.
+
+ ok markus@
+
+20100511
+ - (dtucker) [Makefile.in] Bug #1770: Link libopenbsd-compat twice to solve
+ circular dependency problem on old or odd platforms. From Tom Lane, ok
+ djm@.
+ - (djm) [openbsd-compat/openssl-compat.h] Fix build breakage on older
+ libcrypto by defining OPENSSL_[DR]SA_MAX_MODULUS_BITS if they aren't
+ already. ok dtucker@
+
+20100510
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/04/23 01:47:41
+ [ssh-keygen.c]
+ bz#1740: display a more helpful error message when $HOME is
+ inaccessible while trying to create .ssh directory. Based on patch
+ from jchadima AT redhat.com; ok dtucker@
+ - djm@cvs.openbsd.org 2010/04/23 22:27:38
+ [mux.c]
+ set "detach_close" flag when registering channel cleanup callbacks.
+ This causes the channel to close normally when its fds close and
+ hangs when terminating a mux slave using ~. bz#1758; ok markus@
+ - djm@cvs.openbsd.org 2010/04/23 22:42:05
+ [session.c]
+ set stderr to /dev/null for subsystems rather than just closing it.
+ avoids hangs if a subsystem or shell initialisation writes to stderr.
+ bz#1750; ok markus@
+ - djm@cvs.openbsd.org 2010/04/23 22:48:31
+ [ssh-keygen.c]
+ refuse to generate keys longer than OPENSSL_[RD]SA_MAX_MODULUS_BITS,
+ since we would refuse to use them anyway. bz#1516; ok dtucker@
+ - djm@cvs.openbsd.org 2010/04/26 22:28:24
+ [sshconnect2.c]
+ bz#1502: authctxt.success is declared as an int, but passed by
+ reference to function that accepts sig_atomic_t*. Convert it to
+ the latter; ok markus@ dtucker@
+ - djm@cvs.openbsd.org 2010/05/01 02:50:50
+ [PROTOCOL.certkeys]
+ typo; jmeltzer@
+ - dtucker@cvs.openbsd.org 2010/05/05 04:22:09
+ [sftp.c]
+ restore mput and mget which got lost in the tab-completion changes.
+ found by Kenneth Whitaker, ok djm@
+ - djm@cvs.openbsd.org 2010/05/07 11:30:30
+ [auth-options.c auth-options.h auth.c auth.h auth2-pubkey.c]
+ [key.c servconf.c servconf.h sshd.8 sshd_config.5]
+ add some optional indirection to matching of principal names listed
+ in certificates. Currently, a certificate must include the a user's name
+ to be accepted for authentication. This change adds the ability to
+ specify a list of certificate principal names that are acceptable.
+
+ When authenticating using a CA trusted through ~/.ssh/authorized_keys,
+ this adds a new principals="name1[,name2,...]" key option.
+
+ For CAs listed through sshd_config's TrustedCAKeys option, a new config
+ option "AuthorizedPrincipalsFile" specifies a per-user file containing
+ the list of acceptable names.
+
+ If either option is absent, the current behaviour of requiring the
+ username to appear in principals continues to apply.
+
+ These options are useful for role accounts, disjoint account namespaces
+ and "user@realm"-style naming policies in certificates.
+
+ feedback and ok markus@
+ - jmc@cvs.openbsd.org 2010/05/07 12:49:17
+ [sshd_config.5]
+ tweak previous;
+
+20100423
+ - (dtucker) [configure.ac] Bug #1756: Check for the existence of a lib64 dir
+ in the openssl install directory (some newer openssl versions do this on at
+ least some amd64 platforms).
+
+20100418
+ - OpenBSD CVS Sync
+ - jmc@cvs.openbsd.org 2010/04/16 06:45:01
+ [ssh_config.5]
+ tweak previous; ok djm
+ - jmc@cvs.openbsd.org 2010/04/16 06:47:04
+ [ssh-keygen.1 ssh-keygen.c]
+ tweak previous; ok djm
+ - djm@cvs.openbsd.org 2010/04/16 21:14:27
+ [sshconnect.c]
+ oops, %r => remote username, not %u
+ - djm@cvs.openbsd.org 2010/04/16 01:58:45
+ [regress/cert-hostkey.sh regress/cert-userkey.sh]
+ regression tests for v01 certificate format
+ includes interop tests for v00 certs
+ - (dtucker) [contrib/aix/buildbff.sh] Fix creation of ssh_prng_cmds.default
+ file.
+
+20100416
+ - (djm) Release openssh-5.5p1
+ - OpenBSD CVS Sync
+ - djm@cvs.openbsd.org 2010/03/26 03:13:17
+ [bufaux.c]
+ allow buffer_get_int_ret/buffer_get_int64_ret to take a NULL pointer
+ argument to allow skipping past values in a buffer
+ - jmc@cvs.openbsd.org 2010/03/26 06:54:36
+ [ssh.1]
+ tweak previous;
+ - jmc@cvs.openbsd.org 2010/03/27 14:26:55
+ [ssh_config.5]
+ tweak previous; ok dtucker
+ - djm@cvs.openbsd.org 2010/04/10 00:00:16
+ [ssh.c]
+ bz#1746 - suppress spurious tty warning when using -O and stdin
+ is not a tty; ok dtucker@ markus@
+ - djm@cvs.openbsd.org 2010/04/10 00:04:30
+ [sshconnect.c]
+ fix terminology: we didn't find a certificate in known_hosts, we found
+ a CA key
+ - djm@cvs.openbsd.org 2010/04/10 02:08:44
+ [clientloop.c]
+ bz#1698: kill channel when pty allocation requests fail. Fixed
+ stuck client if the server refuses pty allocation.
+ ok dtucker@ "think so" markus@
+ - djm@cvs.openbsd.org 2010/04/10 02:10:56
+ [sshconnect2.c]
+ show the key type that we are offering in debug(), helps distinguish
+ between certs and plain keys as the path to the private key is usually
+ the same.
+ - djm@cvs.openbsd.org 2010/04/10 05:48:16
+ [mux.c]
+ fix NULL dereference; from matthew.haub AT alumni.adelaide.edu.au
+ - djm@cvs.openbsd.org 2010/04/14 22:27:42
+ [ssh_config.5 sshconnect.c]
+ expand %r => remote username in ssh_config:ProxyCommand;
+ ok deraadt markus
+ - markus@cvs.openbsd.org 2010/04/15 20:32:55
+ [ssh-pkcs11.c]
+ retry lookup for private key if there's no matching key with CKA_SIGN
+ attribute enabled; this fixes fixes MuscleCard support (bugzilla #1736)
+ ok djm@
+ - djm@cvs.openbsd.org 2010/04/16 01:47:26
+ [PROTOCOL.certkeys auth-options.c auth-options.h auth-rsa.c]
+ [auth2-pubkey.c authfd.c key.c key.h myproposal.h ssh-add.c]
+ [ssh-agent.c ssh-dss.c ssh-keygen.1 ssh-keygen.c ssh-rsa.c]
+ [sshconnect.c sshconnect2.c sshd.c]
+ revised certificate format ssh-{dss,rsa}-cert-v01@openssh.com with the
+ following changes:
+
+ move the nonce field to the beginning of the certificate where it can
+ better protect against chosen-prefix attacks on the signature hash
+
+ Rename "constraints" field to "critical options"
+
+ Add a new non-critical "extensions" field
+
+ Add a serial number
+
+ The older format is still support for authentication and cert generation
+ (use "ssh-keygen -t v00 -s ca_key ..." to generate a v00 certificate)
+
+ ok markus@
+
20100410
- (dtucker) [configure.ac] Put the check for the existence of getaddrinfo
back so we disable the IPv6 tests if we don't have it.
diff --git a/crypto/openssh/PROTOCOL.certkeys b/crypto/openssh/PROTOCOL.certkeys
index 1ed9e20..1d1be13 100644
--- a/crypto/openssh/PROTOCOL.certkeys
+++ b/crypto/openssh/PROTOCOL.certkeys
@@ -16,7 +16,7 @@ These protocol extensions build on the simple public key authentication
system already in SSH to allow certificate-based authentication.
The certificates used are not traditional X.509 certificates, with
numerous options and complex encoding rules, but something rather
-more minimal: a key, some identity information and usage constraints
+more minimal: a key, some identity information and usage options
that have been signed with some other trusted key.
A sshd server may be configured to allow authentication via certified
@@ -27,7 +27,7 @@ of acceptance of certified host keys, by adding a similar ability
to specify CA keys in ~/.ssh/known_hosts.
Certified keys are represented using two new key types:
-ssh-rsa-cert-v00@openssh.com and ssh-dss-cert-v00@openssh.com that
+ssh-rsa-cert-v01@openssh.com and ssh-dss-cert-v01@openssh.com that
include certification information along with the public key that is used
to sign challenges. ssh-keygen performs the CA signing operation.
@@ -47,7 +47,7 @@ in RFC4252 section 7.
New public key formats
----------------------
-The ssh-rsa-cert-v00@openssh.com and ssh-dss-cert-v00@openssh.com key
+The ssh-rsa-cert-v01@openssh.com and ssh-dss-cert-v01@openssh.com key
types take a similar high-level format (note: data types and
encoding are as per RFC4251 section 5). The serialised wire encoding of
these certificates is also used for storing them on disk.
@@ -57,42 +57,55 @@ these certificates is also used for storing them on disk.
RSA certificate
- string "ssh-rsa-cert-v00@openssh.com"
+ string "ssh-rsa-cert-v01@openssh.com"
+ string nonce
mpint e
mpint n
+ uint64 serial
uint32 type
string key id
string valid principals
uint64 valid after
uint64 valid before
- string constraints
- string nonce
+ string critical options
+ string extensions
string reserved
string signature key
string signature
DSA certificate
- string "ssh-dss-cert-v00@openssh.com"
+ string "ssh-dss-cert-v01@openssh.com"
+ string nonce
mpint p
mpint q
mpint g
mpint y
+ uint64 serial
uint32 type
string key id
string valid principals
uint64 valid after
uint64 valid before
- string constraints
- string nonce
+ string critical options
+ string extensions
string reserved
string signature key
string signature
+The nonce field is a CA-provided random bitstring of arbitrary length
+(but typically 16 or 32 bytes) included to make attacks that depend on
+inducing collisions in the signature hash infeasible.
+
e and n are the RSA exponent and public modulus respectively.
p, q, g, y are the DSA parameters as described in FIPS-186-2.
+serial is an optional certificate serial number set by the CA to
+provide an abbreviated way to refer to certificates from that CA.
+If a CA does not wish to number its certificates it must set this
+field to zero.
+
type specifies whether this certificate is for identification of a user
or a host using a SSH_CERT_TYPE_... value.
@@ -112,13 +125,15 @@ certificate. Each represents a time in seconds since 1970-01-01
00:00:00. A certificate is considered valid if:
valid after <= current time < valid before
-constraints is a set of zero or more key constraints encoded as below.
+criticial options is a set of zero or more key options encoded as
+below. All such options are "critical" in the sense that an implementation
+must refuse to authorise a key that has an unrecognised option.
-The nonce field is a CA-provided random bitstring of arbitrary length
-(but typically 16 or 32 bytes) included to make attacks that depend on
-inducing collisions in the signature hash infeasible.
+extensions is a set of zero or more optional extensions. These extensions
+are not critical, and an implementation that encounters one that it does
+not recognise may safely ignore it.
-The reserved field is current unused and is ignored in this version of
+The reserved field is currently unused and is ignored in this version of
the protocol.
signature key contains the CA key used to sign the certificate.
@@ -132,22 +147,25 @@ up to, and including the signature key. Signatures are computed and
encoded according to the rules defined for the CA's public key algorithm
(RFC4253 section 6.6 for ssh-rsa and ssh-dss).
-Constraints
------------
+Critical options
+----------------
-The constraints section of the certificate specifies zero or more
-constraints on the certificates validity. The format of this field
+The critical options section of the certificate specifies zero or more
+options on the certificates validity. The format of this field
is a sequence of zero or more tuples:
string name
string data
-The name field identifies the constraint and the data field encodes
-constraint-specific information (see below). All constraints are
-"critical", if an implementation does not recognise a constraint
+Options must be lexically ordered by "name" if they appear in the
+sequence.
+
+The name field identifies the option and the data field encodes
+option-specific information (see below). All options are
+"critical", if an implementation does not recognise a option
then the validating party should refuse to accept the certificate.
-The supported constraints and the contents and structure of their
+The supported options and the contents and structure of their
data fields are:
Name Format Description
@@ -157,37 +175,51 @@ force-command string Specifies a command that is executed
ssh command-line) whenever this key is
used for authentication.
+source-address string Comma-separated list of source addresses
+ from which this certificate is accepted
+ for authentication. Addresses are
+ specified in CIDR format (nn.nn.nn.nn/nn
+ or hhhh::hhhh/nn).
+ If this option is not present then
+ certificates may be presented from any
+ source address.
+
+Extensions
+----------
+
+The extensions section of the certificate specifies zero or more
+non-critical certificate extensions. The encoding and ordering of
+extensions in this field is identical to that of the critical options.
+If an implementation does not recognise an extension, then it should
+ignore it.
+
+The supported extensions and the contents and structure of their data
+fields are:
+
+Name Format Description
+-----------------------------------------------------------------------------
permit-X11-forwarding empty Flag indicating that X11 forwarding
should be permitted. X11 forwarding will
- be refused if this constraint is absent.
+ be refused if this option is absent.
permit-agent-forwarding empty Flag indicating that agent forwarding
should be allowed. Agent forwarding
must not be permitted unless this
- constraint is present.
+ option is present.
permit-port-forwarding empty Flag indicating that port-forwarding
- should be allowed. If this constraint is
+ should be allowed. If this option is
not present then no port forwarding will
be allowed.
permit-pty empty Flag indicating that PTY allocation
should be permitted. In the absence of
- this constraint PTY allocation will be
+ this option PTY allocation will be
disabled.
permit-user-rc empty Flag indicating that execution of
~/.ssh/rc should be permitted. Execution
of this script will not be permitted if
- this constraint is not present.
-
-source-address string Comma-separated list of source addresses
- from which this certificate is accepted
- for authentication. Addresses are
- specified in CIDR format (nn.nn.nn.nn/nn
- or hhhh::hhhh/nn).
- If this constraint is not present then
- certificates may be presented from any
- source address.
+ this option is not present.
-$OpenBSD: PROTOCOL.certkeys,v 1.3 2010/03/03 22:50:40 djm Exp $
+$OpenBSD: PROTOCOL.certkeys,v 1.7 2010/08/04 05:40:39 djm Exp $
diff --git a/crypto/openssh/PROTOCOL.mux b/crypto/openssh/PROTOCOL.mux
index d22f737..1d8c463 100644
--- a/crypto/openssh/PROTOCOL.mux
+++ b/crypto/openssh/PROTOCOL.mux
@@ -109,8 +109,14 @@ A client may request the master to establish a port forward:
forwarding type may be MUX_FWD_LOCAL, MUX_FWD_REMOTE, MUX_FWD_DYNAMIC.
-A server may reply with a MUX_S_OK, a MUX_S_PERMISSION_DENIED or a
-MUX_S_FAILURE.
+A server may reply with a MUX_S_OK, a MUX_S_REMOTE_PORT, a
+MUX_S_PERMISSION_DENIED or a MUX_S_FAILURE.
+
+For dynamically allocated listen port the server replies with
+
+ uint32 MUX_S_REMOTE_PORT
+ uint32 client request id
+ uint32 allocated remote listen port
5. Requesting closure of port forwards
@@ -178,6 +184,7 @@ The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
#define MUX_S_EXIT_MESSAGE 0x80000004
#define MUX_S_ALIVE 0x80000005
#define MUX_S_SESSION_OPENED 0x80000006
+#define MUX_S_REMOTE_PORT 0x80000007
#define MUX_FWD_LOCAL 1
#define MUX_FWD_REMOTE 2
@@ -193,4 +200,4 @@ XXX server->client error/warning notifications
XXX port0 rfwd (need custom response message)
XXX send signals via mux
-$OpenBSD: PROTOCOL.mux,v 1.1 2010/01/26 01:28:35 djm Exp $
+$OpenBSD: PROTOCOL.mux,v 1.2 2010/05/16 12:55:51 markus Exp $
diff --git a/crypto/openssh/README b/crypto/openssh/README
index a29f200..4eaa545 100644
--- a/crypto/openssh/README
+++ b/crypto/openssh/README
@@ -1,4 +1,4 @@
-See http://www.openssh.com/txt/release-5.5 for the release notes.
+See http://www.openssh.com/txt/release-5.6 for the release notes.
- A Japanese translation of this document and of the OpenSSH FAQ is
- available at http://www.unixuser.org/~haruyama/security/openssh/index.html
@@ -62,4 +62,4 @@ References -
[6] http://www.openbsd.org/cgi-bin/man.cgi?query=style&sektion=9
[7] http://www.openssh.com/faq.html
-$Id: README,v 1.73 2010/03/21 19:11:55 djm Exp $
+$Id: README,v 1.74 2010/08/08 16:32:06 djm Exp $
diff --git a/crypto/openssh/auth-options.c b/crypto/openssh/auth-options.c
index 69b314f..a704024 100644
--- a/crypto/openssh/auth-options.c
+++ b/crypto/openssh/auth-options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth-options.c,v 1.49 2010/03/16 15:46:52 stevesk Exp $ */
+/* $OpenBSD: auth-options.c,v 1.52 2010/05/20 23:46:02 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -27,10 +27,10 @@
#include "canohost.h"
#include "buffer.h"
#include "channels.h"
-#include "auth-options.h"
#include "servconf.h"
#include "misc.h"
#include "key.h"
+#include "auth-options.h"
#include "hostfile.h"
#include "auth.h"
#ifdef GSSAPI
@@ -55,6 +55,9 @@ struct envstring *custom_environment = NULL;
/* "tunnel=" option. */
int forced_tun_device = -1;
+/* "principals=" option. */
+char *authorized_principals = NULL;
+
extern ServerOptions options;
void
@@ -76,6 +79,10 @@ auth_clear_options(void)
xfree(forced_command);
forced_command = NULL;
}
+ if (authorized_principals) {
+ xfree(authorized_principals);
+ authorized_principals = NULL;
+ }
forced_tun_device = -1;
channel_clear_permitted_opens();
}
@@ -141,6 +148,8 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
cp = "command=\"";
if (strncasecmp(opts, cp, strlen(cp)) == 0) {
opts += strlen(cp);
+ if (forced_command != NULL)
+ xfree(forced_command);
forced_command = xmalloc(strlen(opts) + 1);
i = 0;
while (*opts) {
@@ -167,6 +176,38 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
opts++;
goto next_option;
}
+ cp = "principals=\"";
+ if (strncasecmp(opts, cp, strlen(cp)) == 0) {
+ opts += strlen(cp);
+ if (authorized_principals != NULL)
+ xfree(authorized_principals);
+ authorized_principals = xmalloc(strlen(opts) + 1);
+ i = 0;
+ while (*opts) {
+ if (*opts == '"')
+ break;
+ if (*opts == '\\' && opts[1] == '"') {
+ opts += 2;
+ authorized_principals[i++] = '"';
+ continue;
+ }
+ authorized_principals[i++] = *opts++;
+ }
+ if (!*opts) {
+ debug("%.100s, line %lu: missing end quote",
+ file, linenum);
+ auth_debug_add("%.100s, line %lu: missing end quote",
+ file, linenum);
+ xfree(authorized_principals);
+ authorized_principals = NULL;
+ goto bad_option;
+ }
+ authorized_principals[i] = '\0';
+ auth_debug_add("principals: %.900s",
+ authorized_principals);
+ opts++;
+ goto next_option;
+ }
cp = "environment=\"";
if (options.permit_user_env &&
strncasecmp(opts, cp, strlen(cp)) == 0) {
@@ -376,123 +417,147 @@ bad_option:
return 0;
}
-/*
- * Set options from certificate constraints. These supersede user key options
- * so this must be called after auth_parse_options().
- */
-int
-auth_cert_constraints(Buffer *c_orig, struct passwd *pw)
+#define OPTIONS_CRITICAL 1
+#define OPTIONS_EXTENSIONS 2
+static int
+parse_option_list(u_char *optblob, size_t optblob_len, struct passwd *pw,
+ u_int which, int crit,
+ int *cert_no_port_forwarding_flag,
+ int *cert_no_agent_forwarding_flag,
+ int *cert_no_x11_forwarding_flag,
+ int *cert_no_pty_flag,
+ int *cert_no_user_rc,
+ char **cert_forced_command,
+ int *cert_source_address_done)
{
+ char *command, *allowed;
+ const char *remote_ip;
u_char *name = NULL, *data_blob = NULL;
u_int nlen, dlen, clen;
Buffer c, data;
- int ret = -1;
-
- int cert_no_port_forwarding_flag = 1;
- int cert_no_agent_forwarding_flag = 1;
- int cert_no_x11_forwarding_flag = 1;
- int cert_no_pty_flag = 1;
- int cert_no_user_rc = 1;
- char *cert_forced_command = NULL;
- int cert_source_address_done = 0;
+ int ret = -1, found;
buffer_init(&data);
/* Make copy to avoid altering original */
buffer_init(&c);
- buffer_append(&c, buffer_ptr(c_orig), buffer_len(c_orig));
+ buffer_append(&c, optblob, optblob_len);
while (buffer_len(&c) > 0) {
if ((name = buffer_get_string_ret(&c, &nlen)) == NULL ||
(data_blob = buffer_get_string_ret(&c, &dlen)) == NULL) {
- error("Certificate constraints corrupt");
+ error("Certificate options corrupt");
goto out;
}
buffer_append(&data, data_blob, dlen);
- debug3("found certificate constraint \"%.100s\" len %u",
+ debug3("found certificate option \"%.100s\" len %u",
name, dlen);
if (strlen(name) != nlen) {
error("Certificate constraint name contains \\0");
goto out;
}
- if (strcmp(name, "permit-X11-forwarding") == 0)
- cert_no_x11_forwarding_flag = 0;
- else if (strcmp(name, "permit-agent-forwarding") == 0)
- cert_no_agent_forwarding_flag = 0;
- else if (strcmp(name, "permit-port-forwarding") == 0)
- cert_no_port_forwarding_flag = 0;
- else if (strcmp(name, "permit-pty") == 0)
- cert_no_pty_flag = 0;
- else if (strcmp(name, "permit-user-rc") == 0)
- cert_no_user_rc = 0;
- else if (strcmp(name, "force-command") == 0) {
- char *command = buffer_get_string_ret(&data, &clen);
-
- if (command == NULL) {
- error("Certificate constraint \"%s\" corrupt",
- name);
- goto out;
+ found = 0;
+ if ((which & OPTIONS_EXTENSIONS) != 0) {
+ if (strcmp(name, "permit-X11-forwarding") == 0) {
+ *cert_no_x11_forwarding_flag = 0;
+ found = 1;
+ } else if (strcmp(name,
+ "permit-agent-forwarding") == 0) {
+ *cert_no_agent_forwarding_flag = 0;
+ found = 1;
+ } else if (strcmp(name,
+ "permit-port-forwarding") == 0) {
+ *cert_no_port_forwarding_flag = 0;
+ found = 1;
+ } else if (strcmp(name, "permit-pty") == 0) {
+ *cert_no_pty_flag = 0;
+ found = 1;
+ } else if (strcmp(name, "permit-user-rc") == 0) {
+ *cert_no_user_rc = 0;
+ found = 1;
}
- if (strlen(command) != clen) {
- error("force-command constraint contains \\0");
- goto out;
- }
- if (cert_forced_command != NULL) {
- error("Certificate has multiple "
- "force-command constraints");
- xfree(command);
- goto out;
- }
- cert_forced_command = command;
- } else if (strcmp(name, "source-address") == 0) {
- char *allowed = buffer_get_string_ret(&data, &clen);
- const char *remote_ip = get_remote_ipaddr();
-
- if (allowed == NULL) {
- error("Certificate constraint \"%s\" corrupt",
- name);
- goto out;
- }
- if (strlen(allowed) != clen) {
- error("source-address constraint contains \\0");
- goto out;
- }
- if (cert_source_address_done++) {
- error("Certificate has multiple "
- "source-address constraints");
- xfree(allowed);
- goto out;
+ }
+ if (!found && (which & OPTIONS_CRITICAL) != 0) {
+ if (strcmp(name, "force-command") == 0) {
+ if ((command = buffer_get_string_ret(&data,
+ &clen)) == NULL) {
+ error("Certificate constraint \"%s\" "
+ "corrupt", name);
+ goto out;
+ }
+ if (strlen(command) != clen) {
+ error("force-command constraint "
+ "contains \\0");
+ goto out;
+ }
+ if (*cert_forced_command != NULL) {
+ error("Certificate has multiple "
+ "force-command options");
+ xfree(command);
+ goto out;
+ }
+ *cert_forced_command = command;
+ found = 1;
}
- switch (addr_match_cidr_list(remote_ip, allowed)) {
- case 1:
- /* accepted */
- xfree(allowed);
- break;
- case 0:
- /* no match */
- logit("Authentication tried for %.100s with "
- "valid certificate but not from a "
- "permitted host (ip=%.200s).",
- pw->pw_name, remote_ip);
- auth_debug_add("Your address '%.200s' is not "
- "permitted to use this certificate for "
- "login.", remote_ip);
- xfree(allowed);
- goto out;
- case -1:
- error("Certificate source-address contents "
- "invalid");
- xfree(allowed);
- goto out;
+ if (strcmp(name, "source-address") == 0) {
+ if ((allowed = buffer_get_string_ret(&data,
+ &clen)) == NULL) {
+ error("Certificate constraint "
+ "\"%s\" corrupt", name);
+ goto out;
+ }
+ if (strlen(allowed) != clen) {
+ error("source-address constraint "
+ "contains \\0");
+ goto out;
+ }
+ if ((*cert_source_address_done)++) {
+ error("Certificate has multiple "
+ "source-address options");
+ xfree(allowed);
+ goto out;
+ }
+ remote_ip = get_remote_ipaddr();
+ switch (addr_match_cidr_list(remote_ip,
+ allowed)) {
+ case 1:
+ /* accepted */
+ xfree(allowed);
+ break;
+ case 0:
+ /* no match */
+ logit("Authentication tried for %.100s "
+ "with valid certificate but not "
+ "from a permitted host "
+ "(ip=%.200s).", pw->pw_name,
+ remote_ip);
+ auth_debug_add("Your address '%.200s' "
+ "is not permitted to use this "
+ "certificate for login.",
+ remote_ip);
+ xfree(allowed);
+ goto out;
+ case -1:
+ error("Certificate source-address "
+ "contents invalid");
+ xfree(allowed);
+ goto out;
+ }
+ found = 1;
}
- } else {
- error("Certificate constraint \"%s\" is not supported",
- name);
- goto out;
}
- if (buffer_len(&data) != 0) {
- error("Certificate constraint \"%s\" corrupt "
+ if (!found) {
+ if (crit) {
+ error("Certificate critical option \"%s\" "
+ "is not supported", name);
+ goto out;
+ } else {
+ logit("Certificate extension \"%s\" "
+ "is not supported", name);
+ }
+ } else if (buffer_len(&data) != 0) {
+ error("Certificate option \"%s\" corrupt "
"(extra data)", name);
goto out;
}
@@ -501,10 +566,73 @@ auth_cert_constraints(Buffer *c_orig, struct passwd *pw)
xfree(data_blob);
name = data_blob = NULL;
}
-
- /* successfully parsed all constraints */
+ /* successfully parsed all options */
ret = 0;
+ out:
+ if (ret != 0 &&
+ cert_forced_command != NULL &&
+ *cert_forced_command != NULL) {
+ xfree(*cert_forced_command);
+ *cert_forced_command = NULL;
+ }
+ if (name != NULL)
+ xfree(name);
+ if (data_blob != NULL)
+ xfree(data_blob);
+ buffer_free(&data);
+ buffer_free(&c);
+ return ret;
+}
+
+/*
+ * Set options from critical certificate options. These supersede user key
+ * options so this must be called after auth_parse_options().
+ */
+int
+auth_cert_options(Key *k, struct passwd *pw)
+{
+ int cert_no_port_forwarding_flag = 1;
+ int cert_no_agent_forwarding_flag = 1;
+ int cert_no_x11_forwarding_flag = 1;
+ int cert_no_pty_flag = 1;
+ int cert_no_user_rc = 1;
+ char *cert_forced_command = NULL;
+ int cert_source_address_done = 0;
+
+ if (key_cert_is_legacy(k)) {
+ /* All options are in the one field for v00 certs */
+ if (parse_option_list(buffer_ptr(&k->cert->critical),
+ buffer_len(&k->cert->critical), pw,
+ OPTIONS_CRITICAL|OPTIONS_EXTENSIONS, 1,
+ &cert_no_port_forwarding_flag,
+ &cert_no_agent_forwarding_flag,
+ &cert_no_x11_forwarding_flag,
+ &cert_no_pty_flag,
+ &cert_no_user_rc,
+ &cert_forced_command,
+ &cert_source_address_done) == -1)
+ return -1;
+ } else {
+ /* Separate options and extensions for v01 certs */
+ if (parse_option_list(buffer_ptr(&k->cert->critical),
+ buffer_len(&k->cert->critical), pw,
+ OPTIONS_CRITICAL, 1, NULL, NULL, NULL, NULL, NULL,
+ &cert_forced_command,
+ &cert_source_address_done) == -1)
+ return -1;
+ if (parse_option_list(buffer_ptr(&k->cert->extensions),
+ buffer_len(&k->cert->extensions), pw,
+ OPTIONS_EXTENSIONS, 1,
+ &cert_no_port_forwarding_flag,
+ &cert_no_agent_forwarding_flag,
+ &cert_no_x11_forwarding_flag,
+ &cert_no_pty_flag,
+ &cert_no_user_rc,
+ NULL, NULL) == -1)
+ return -1;
+ }
+
no_port_forwarding_flag |= cert_no_port_forwarding_flag;
no_agent_forwarding_flag |= cert_no_agent_forwarding_flag;
no_x11_forwarding_flag |= cert_no_x11_forwarding_flag;
@@ -516,14 +644,6 @@ auth_cert_constraints(Buffer *c_orig, struct passwd *pw)
xfree(forced_command);
forced_command = cert_forced_command;
}
-
- out:
- if (name != NULL)
- xfree(name);
- if (data_blob != NULL)
- xfree(data_blob);
- buffer_free(&data);
- buffer_free(&c);
- return ret;
+ return 0;
}
diff --git a/crypto/openssh/auth-options.h b/crypto/openssh/auth-options.h
index 694edc8..7455c94 100644
--- a/crypto/openssh/auth-options.h
+++ b/crypto/openssh/auth-options.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth-options.h,v 1.18 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: auth-options.h,v 1.20 2010/05/07 11:30:29 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -31,9 +31,10 @@ extern char *forced_command;
extern struct envstring *custom_environment;
extern int forced_tun_device;
extern int key_is_cert_authority;
+extern char *authorized_principals;
int auth_parse_options(struct passwd *, char *, char *, u_long);
void auth_clear_options(void);
-int auth_cert_constraints(Buffer *, struct passwd *);
+int auth_cert_options(Key *, struct passwd *);
#endif
diff --git a/crypto/openssh/auth-rsa.c b/crypto/openssh/auth-rsa.c
index 65571a8..56702d1 100644
--- a/crypto/openssh/auth-rsa.c
+++ b/crypto/openssh/auth-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth-rsa.c,v 1.74 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: auth-rsa.c,v 1.78 2010/07/13 23:13:16 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -34,11 +34,11 @@
#include "uidswap.h"
#include "match.h"
#include "buffer.h"
-#include "auth-options.h"
#include "pathnames.h"
#include "log.h"
#include "servconf.h"
#include "key.h"
+#include "auth-options.h"
#include "hostfile.h"
#include "auth.h"
#ifdef GSSAPI
@@ -116,7 +116,7 @@ auth_rsa_verify_response(Key *key, BIGNUM *challenge, u_char response[16])
MD5_Final(mdbuf, &md);
/* Verify that the response is the original challenge. */
- if (memcmp(response, mdbuf, 16) != 0) {
+ if (timingsafe_bcmp(response, mdbuf, 16) != 0) {
/* Wrong answer. */
return (0);
}
@@ -256,7 +256,8 @@ auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey)
*/
if (!auth_parse_options(pw, key_options, file, linenum))
continue;
-
+ if (key_is_cert_authority)
+ continue;
/* break out, this key is allowed */
allowed = 1;
break;
diff --git a/crypto/openssh/auth.c b/crypto/openssh/auth.c
index 2917414..c50db1e 100644
--- a/crypto/openssh/auth.c
+++ b/crypto/openssh/auth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.c,v 1.86 2010/03/05 02:58:11 djm Exp $ */
+/* $OpenBSD: auth.c,v 1.89 2010/08/04 05:42:47 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -144,7 +144,7 @@ allowed_user(struct passwd * pw)
locked = 1;
#endif
#ifdef USE_LIBIAF
- free(passwd);
+ free((void *) passwd);
#endif /* USE_LIBIAF */
if (locked) {
logit("User %.100s not allowed because account is locked",
@@ -367,6 +367,14 @@ authorized_keys_file2(struct passwd *pw)
return expand_authorized_keys(options.authorized_keys_file2, pw);
}
+char *
+authorized_principals_file(struct passwd *pw)
+{
+ if (options.authorized_principals_file == NULL)
+ return NULL;
+ return expand_authorized_keys(options.authorized_principals_file, pw);
+}
+
/* return ok if key exists in sysfile or userfile */
HostStatus
check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
@@ -378,7 +386,7 @@ check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
HostStatus host_status;
/* Check if we know the host and its host key. */
- found = key_new(key->type);
+ found = key_new(key_is_cert(key) ? KEY_UNSPEC : key->type);
host_status = check_host_in_hostfile(sysfile, host, key, found, NULL);
if (host_status != HOST_OK && userfile != NULL) {
@@ -390,6 +398,8 @@ check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host,
logit("Authentication refused for %.100s: "
"bad owner or modes for %.200s",
pw->pw_name, user_hostfile);
+ auth_debug_add("Ignored %.200s: bad ownership or modes",
+ user_hostfile);
} else {
temporarily_use_uid(pw);
host_status = check_host_in_hostfile(user_hostfile,
@@ -478,21 +488,18 @@ secure_filename(FILE *f, const char *file, struct passwd *pw,
return 0;
}
-FILE *
-auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
+static FILE *
+auth_openfile(const char *file, struct passwd *pw, int strict_modes,
+ int log_missing, char *file_type)
{
char line[1024];
struct stat st;
int fd;
FILE *f;
- /*
- * Open the file containing the authorized keys
- * Fail quietly if file does not exist
- */
if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) {
- if (errno != ENOENT)
- debug("Could not open keyfile '%s': %s", file,
+ if (log_missing || errno != ENOENT)
+ debug("Could not open %s '%s': %s", file_type, file,
strerror(errno));
return NULL;
}
@@ -502,8 +509,8 @@ auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
return NULL;
}
if (!S_ISREG(st.st_mode)) {
- logit("User %s authorized keys %s is not a regular file",
- pw->pw_name, file);
+ logit("User %s %s %s is not a regular file",
+ pw->pw_name, file_type, file);
close(fd);
return NULL;
}
@@ -516,12 +523,27 @@ auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
secure_filename(f, file, pw, line, sizeof(line)) != 0) {
fclose(f);
logit("Authentication refused: %s", line);
+ auth_debug_add("Ignored %s: %s", file_type, line);
return NULL;
}
return f;
}
+
+FILE *
+auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes)
+{
+ return auth_openfile(file, pw, strict_modes, 1, "authorized keys");
+}
+
+FILE *
+auth_openprincipals(const char *file, struct passwd *pw, int strict_modes)
+{
+ return auth_openfile(file, pw, strict_modes, 0,
+ "authorized principals");
+}
+
struct passwd *
getpwnamallow(const char *user)
{
diff --git a/crypto/openssh/auth.h b/crypto/openssh/auth.h
index a65b87d..77317ae 100644
--- a/crypto/openssh/auth.h
+++ b/crypto/openssh/auth.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.h,v 1.65 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: auth.h,v 1.66 2010/05/07 11:30:29 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -169,8 +169,10 @@ void abandon_challenge_response(Authctxt *);
char *authorized_keys_file(struct passwd *);
char *authorized_keys_file2(struct passwd *);
+char *authorized_principals_file(struct passwd *);
FILE *auth_openkeyfile(const char *, struct passwd *, int);
+FILE *auth_openprincipals(const char *, struct passwd *, int);
int auth_key_is_revoked(Key *);
HostStatus
diff --git a/crypto/openssh/auth1.c b/crypto/openssh/auth1.c
index 1801661..bf442db 100644
--- a/crypto/openssh/auth1.c
+++ b/crypto/openssh/auth1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth1.c,v 1.73 2008/07/04 23:30:16 djm Exp $ */
+/* $OpenBSD: auth1.c,v 1.74 2010/06/25 08:46:17 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -244,7 +244,7 @@ do_authloop(Authctxt *authctxt)
authctxt->valid ? "" : "invalid user ", authctxt->user);
/* If the user has no password, accept authentication immediately. */
- if (options.password_authentication &&
+ if (options.permit_empty_passwd && options.password_authentication &&
#ifdef KRB5
(!options.kerberos_authentication || options.kerberos_or_local_passwd) &&
#endif
diff --git a/crypto/openssh/auth2-hostbased.c b/crypto/openssh/auth2-hostbased.c
index 7216465..cdf442f 100644
--- a/crypto/openssh/auth2-hostbased.c
+++ b/crypto/openssh/auth2-hostbased.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth2-hostbased.c,v 1.13 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: auth2-hostbased.c,v 1.14 2010/08/04 05:42:47 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -141,9 +141,10 @@ int
hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
Key *key)
{
- const char *resolvedname, *ipaddr, *lookup;
+ const char *resolvedname, *ipaddr, *lookup, *reason;
HostStatus host_status;
int len;
+ char *fp;
if (auth_key_is_revoked(key))
return 0;
@@ -174,16 +175,40 @@ hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
}
debug2("userauth_hostbased: access allowed by auth_rhosts2");
+ if (key_is_cert(key) &&
+ key_cert_check_authority(key, 1, 0, lookup, &reason)) {
+ error("%s", reason);
+ auth_debug_add("%s", reason);
+ return 0;
+ }
+
host_status = check_key_in_hostfiles(pw, key, lookup,
_PATH_SSH_SYSTEM_HOSTFILE,
options.ignore_user_known_hosts ? NULL : _PATH_SSH_USER_HOSTFILE);
/* backward compat if no key has been found. */
- if (host_status == HOST_NEW)
+ if (host_status == HOST_NEW) {
host_status = check_key_in_hostfiles(pw, key, lookup,
_PATH_SSH_SYSTEM_HOSTFILE2,
options.ignore_user_known_hosts ? NULL :
_PATH_SSH_USER_HOSTFILE2);
+ }
+
+ if (host_status == HOST_OK) {
+ if (key_is_cert(key)) {
+ fp = key_fingerprint(key->cert->signature_key,
+ SSH_FP_MD5, SSH_FP_HEX);
+ verbose("Accepted certificate ID \"%s\" signed by "
+ "%s CA %s from %s@%s", key->cert->key_id,
+ key_type(key->cert->signature_key), fp,
+ cuser, lookup);
+ } else {
+ fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
+ verbose("Accepted %s public key %s from %s@%s",
+ key_type(key), fp, cuser, lookup);
+ }
+ xfree(fp);
+ }
return (host_status == HOST_OK);
}
diff --git a/crypto/openssh/auth2-none.c b/crypto/openssh/auth2-none.c
index 08f2f93..c8c6c74 100644
--- a/crypto/openssh/auth2-none.c
+++ b/crypto/openssh/auth2-none.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth2-none.c,v 1.15 2008/07/02 12:36:39 djm Exp $ */
+/* $OpenBSD: auth2-none.c,v 1.16 2010/06/25 08:46:17 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -61,7 +61,7 @@ userauth_none(Authctxt *authctxt)
{
none_enabled = 0;
packet_check_eom();
- if (options.password_authentication)
+ if (options.permit_empty_passwd && options.password_authentication)
return (PRIVSEP(auth_password(authctxt, "")));
return (0);
}
diff --git a/crypto/openssh/auth2-pubkey.c b/crypto/openssh/auth2-pubkey.c
index c4cadf4..35cf79c 100644
--- a/crypto/openssh/auth2-pubkey.c
+++ b/crypto/openssh/auth2-pubkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth2-pubkey.c,v 1.22 2010/03/10 23:27:17 djm Exp $ */
+/* $OpenBSD: auth2-pubkey.c,v 1.26 2010/06/29 23:16:46 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -57,6 +57,7 @@
#include "monitor_wrap.h"
#include "misc.h"
#include "authfile.h"
+#include "match.h"
/* import */
extern ServerOptions options;
@@ -176,6 +177,83 @@ done:
return authenticated;
}
+static int
+match_principals_option(const char *principal_list, struct KeyCert *cert)
+{
+ char *result;
+ u_int i;
+
+ /* XXX percent_expand() sequences for authorized_principals? */
+
+ for (i = 0; i < cert->nprincipals; i++) {
+ if ((result = match_list(cert->principals[i],
+ principal_list, NULL)) != NULL) {
+ debug3("matched principal from key options \"%.100s\"",
+ result);
+ xfree(result);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int
+match_principals_file(char *file, struct passwd *pw, struct KeyCert *cert)
+{
+ FILE *f;
+ char line[SSH_MAX_PUBKEY_BYTES], *cp, *ep, *line_opts;
+ u_long linenum = 0;
+ u_int i;
+
+ temporarily_use_uid(pw);
+ debug("trying authorized principals file %s", file);
+ if ((f = auth_openprincipals(file, pw, options.strict_modes)) == NULL) {
+ restore_uid();
+ return 0;
+ }
+ while (read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) {
+ /* Skip leading whitespace. */
+ for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
+ ;
+ /* Skip blank and comment lines. */
+ if ((ep = strchr(cp, '#')) != NULL)
+ *ep = '\0';
+ if (!*cp || *cp == '\n')
+ continue;
+ /* Trim trailing whitespace. */
+ ep = cp + strlen(cp) - 1;
+ while (ep > cp && (*ep == '\n' || *ep == ' ' || *ep == '\t'))
+ *ep-- = '\0';
+ /*
+ * If the line has internal whitespace then assume it has
+ * key options.
+ */
+ line_opts = NULL;
+ if ((ep = strrchr(cp, ' ')) != NULL ||
+ (ep = strrchr(cp, '\t')) != NULL) {
+ for (; *ep == ' ' || *ep == '\t'; ep++)
+ ;;
+ line_opts = cp;
+ cp = ep;
+ }
+ for (i = 0; i < cert->nprincipals; i++) {
+ if (strcmp(cp, cert->principals[i]) == 0) {
+ debug3("matched principal from file \"%.100s\"",
+ cert->principals[i]);
+ if (auth_parse_options(pw, line_opts,
+ file, linenum) != 1)
+ continue;
+ fclose(f);
+ restore_uid();
+ return 1;
+ }
+ }
+ }
+ fclose(f);
+ restore_uid();
+ return 0;
+}
+
/* return 1 if user allows given key */
static int
user_key_allowed2(struct passwd *pw, Key *key, char *file)
@@ -233,26 +311,39 @@ user_key_allowed2(struct passwd *pw, Key *key, char *file)
continue;
}
}
- if (auth_parse_options(pw, key_options, file, linenum) != 1)
- continue;
- if (key->type == KEY_RSA_CERT || key->type == KEY_DSA_CERT) {
- if (!key_is_cert_authority)
- continue;
+ if (key_is_cert(key)) {
if (!key_equal(found, key->cert->signature_key))
continue;
+ if (auth_parse_options(pw, key_options, file,
+ linenum) != 1)
+ continue;
+ if (!key_is_cert_authority)
+ continue;
fp = key_fingerprint(found, SSH_FP_MD5,
SSH_FP_HEX);
debug("matching CA found: file %s, line %lu, %s %s",
file, linenum, key_type(found), fp);
- if (key_cert_check_authority(key, 0, 0, pw->pw_name,
- &reason) != 0) {
+ /*
+ * If the user has specified a list of principals as
+ * a key option, then prefer that list to matching
+ * their username in the certificate principals list.
+ */
+ if (authorized_principals != NULL &&
+ !match_principals_option(authorized_principals,
+ key->cert)) {
+ reason = "Certificate does not contain an "
+ "authorized principal";
+ fail_reason:
xfree(fp);
error("%s", reason);
auth_debug_add("%s", reason);
continue;
}
- if (auth_cert_constraints(&key->cert->constraints,
- pw) != 0) {
+ if (key_cert_check_authority(key, 0, 0,
+ authorized_principals == NULL ? pw->pw_name : NULL,
+ &reason) != 0)
+ goto fail_reason;
+ if (auth_cert_options(key, pw) != 0) {
xfree(fp);
continue;
}
@@ -262,7 +353,12 @@ user_key_allowed2(struct passwd *pw, Key *key, char *file)
xfree(fp);
found_key = 1;
break;
- } else if (!key_is_cert_authority && key_equal(found, key)) {
+ } else if (key_equal(found, key)) {
+ if (auth_parse_options(pw, key_options, file,
+ linenum) != 1)
+ continue;
+ if (key_is_cert_authority)
+ continue;
found_key = 1;
debug("matching key found: file %s, line %lu",
file, linenum);
@@ -285,7 +381,7 @@ user_key_allowed2(struct passwd *pw, Key *key, char *file)
static int
user_cert_trusted_ca(struct passwd *pw, Key *key)
{
- char *ca_fp;
+ char *ca_fp, *principals_file = NULL;
const char *reason;
int ret = 0;
@@ -302,12 +398,25 @@ user_cert_trusted_ca(struct passwd *pw, Key *key)
options.trusted_user_ca_keys);
goto out;
}
- if (key_cert_check_authority(key, 0, 1, pw->pw_name, &reason) != 0) {
- error("%s", reason);
- auth_debug_add("%s", reason);
- goto out;
+ /*
+ * If AuthorizedPrincipals is in use, then compare the certificate
+ * principals against the names in that file rather than matching
+ * against the username.
+ */
+ if ((principals_file = authorized_principals_file(pw)) != NULL) {
+ if (!match_principals_file(principals_file, pw, key->cert)) {
+ reason = "Certificate does not contain an "
+ "authorized principal";
+ fail_reason:
+ error("%s", reason);
+ auth_debug_add("%s", reason);
+ goto out;
+ }
}
- if (auth_cert_constraints(&key->cert->constraints, pw) != 0)
+ if (key_cert_check_authority(key, 0, 1,
+ principals_file == NULL ? pw->pw_name : NULL, &reason) != 0)
+ goto fail_reason;
+ if (auth_cert_options(key, pw) != 0)
goto out;
verbose("Accepted certificate ID \"%s\" signed by %s CA %s via %s",
@@ -316,6 +425,8 @@ user_cert_trusted_ca(struct passwd *pw, Key *key)
ret = 1;
out:
+ if (principals_file != NULL)
+ xfree(principals_file);
if (ca_fp != NULL)
xfree(ca_fp);
return ret;
diff --git a/crypto/openssh/authfd.c b/crypto/openssh/authfd.c
index 28a8cf2..739722f 100644
--- a/crypto/openssh/authfd.c
+++ b/crypto/openssh/authfd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfd.c,v 1.82 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: authfd.c,v 1.83 2010/04/16 01:47:26 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -483,6 +483,7 @@ ssh_encode_identity_ssh2(Buffer *b, Key *key, const char *comment)
buffer_put_bignum2(b, key->rsa->p);
buffer_put_bignum2(b, key->rsa->q);
break;
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
if (key->cert == NULL || buffer_len(&key->cert->certblob) == 0)
fatal("%s: no cert/certblob", __func__);
@@ -500,6 +501,7 @@ ssh_encode_identity_ssh2(Buffer *b, Key *key, const char *comment)
buffer_put_bignum2(b, key->dsa->pub_key);
buffer_put_bignum2(b, key->dsa->priv_key);
break;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
if (key->cert == NULL || buffer_len(&key->cert->certblob) == 0)
fatal("%s: no cert/certblob", __func__);
@@ -535,8 +537,10 @@ ssh_add_identity_constrained(AuthenticationConnection *auth, Key *key,
break;
case KEY_RSA:
case KEY_RSA_CERT:
+ case KEY_RSA_CERT_V00:
case KEY_DSA:
case KEY_DSA_CERT:
+ case KEY_DSA_CERT_V00:
type = constrained ?
SSH2_AGENTC_ADD_ID_CONSTRAINED :
SSH2_AGENTC_ADD_IDENTITY;
diff --git a/crypto/openssh/authfile.c b/crypto/openssh/authfile.c
index 224c6aa..2bd8878 100644
--- a/crypto/openssh/authfile.c
+++ b/crypto/openssh/authfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfile.c,v 1.80 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: authfile.c,v 1.82 2010/08/04 05:49:22 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -693,6 +693,66 @@ key_load_public(const char *filename, char **commentp)
return NULL;
}
+/* Load the certificate associated with the named private key */
+Key *
+key_load_cert(const char *filename)
+{
+ Key *pub;
+ char *file;
+
+ pub = key_new(KEY_UNSPEC);
+ xasprintf(&file, "%s-cert.pub", filename);
+ if (key_try_load_public(pub, file, NULL) == 1) {
+ xfree(file);
+ return pub;
+ }
+ xfree(file);
+ key_free(pub);
+ return NULL;
+}
+
+/* Load private key and certificate */
+Key *
+key_load_private_cert(int type, const char *filename, const char *passphrase,
+ int *perm_ok)
+{
+ Key *key, *pub;
+
+ switch (type) {
+ case KEY_RSA:
+ case KEY_DSA:
+ break;
+ default:
+ error("%s: unsupported key type", __func__);
+ return NULL;
+ }
+
+ if ((key = key_load_private_type(type, filename,
+ passphrase, NULL, perm_ok)) == NULL)
+ return NULL;
+
+ if ((pub = key_load_cert(filename)) == NULL) {
+ key_free(key);
+ return NULL;
+ }
+
+ /* Make sure the private key matches the certificate */
+ if (key_equal_public(key, pub) == 0) {
+ error("%s: certificate does not match private key %s",
+ __func__, filename);
+ } else if (key_to_certified(key, key_cert_is_legacy(pub)) != 0) {
+ error("%s: key_to_certified failed", __func__);
+ } else {
+ key_cert_copy(pub, key);
+ key_free(pub);
+ return key;
+ }
+
+ key_free(key);
+ key_free(pub);
+ return NULL;
+}
+
/*
* Returns 1 if the specified "key" is listed in the file "filename",
* 0 if the key is not listed or -1 on error.
diff --git a/crypto/openssh/authfile.h b/crypto/openssh/authfile.h
index 6dfa478..6745dc0 100644
--- a/crypto/openssh/authfile.h
+++ b/crypto/openssh/authfile.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfile.h,v 1.14 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: authfile.h,v 1.15 2010/08/04 05:42:47 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -16,9 +16,11 @@
#define AUTHFILE_H
int key_save_private(Key *, const char *, const char *, const char *);
+Key *key_load_cert(const char *);
Key *key_load_public(const char *, char **);
Key *key_load_public_type(int, const char *, char **);
Key *key_load_private(const char *, const char *, char **);
+Key *key_load_private_cert(int, const char *, const char *, int *);
Key *key_load_private_type(int, const char *, const char *, char **, int *);
Key *key_load_private_pem(int, int, const char *, char **);
int key_perm_ok(int, const char *);
diff --git a/crypto/openssh/bufaux.c b/crypto/openssh/bufaux.c
index 4ef19c4..854fd51 100644
--- a/crypto/openssh/bufaux.c
+++ b/crypto/openssh/bufaux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bufaux.c,v 1.48 2010/02/02 22:49:34 djm Exp $ */
+/* $OpenBSD: bufaux.c,v 1.49 2010/03/26 03:13:17 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -84,7 +84,8 @@ buffer_get_int_ret(u_int *ret, Buffer *buffer)
if (buffer_get_ret(buffer, (char *) buf, 4) == -1)
return (-1);
- *ret = get_u32(buf);
+ if (ret != NULL)
+ *ret = get_u32(buf);
return (0);
}
@@ -106,7 +107,8 @@ buffer_get_int64_ret(u_int64_t *ret, Buffer *buffer)
if (buffer_get_ret(buffer, (char *) buf, 8) == -1)
return (-1);
- *ret = get_u64(buf);
+ if (ret != NULL)
+ *ret = get_u64(buf);
return (0);
}
diff --git a/crypto/openssh/channels.c b/crypto/openssh/channels.c
index a55d278..1cd5004 100644
--- a/crypto/openssh/channels.c
+++ b/crypto/openssh/channels.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.303 2010/01/30 21:12:08 djm Exp $ */
+/* $OpenBSD: channels.c,v 1.309 2010/08/05 13:08:42 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -114,10 +114,10 @@ typedef struct {
} ForwardPermission;
/* List of all permitted host/port pairs to connect by the user. */
-static ForwardPermission permitted_opens[SSH_MAX_FORWARDS_PER_DIRECTION];
+static ForwardPermission *permitted_opens = NULL;
/* List of all permitted host/port pairs to connect by the admin. */
-static ForwardPermission permitted_adm_opens[SSH_MAX_FORWARDS_PER_DIRECTION];
+static ForwardPermission *permitted_adm_opens = NULL;
/* Number of permitted host/port pairs in the array permitted by the user. */
static int num_permitted_opens = 0;
@@ -330,6 +330,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
c->ctl_chan = -1;
c->mux_rcb = NULL;
c->mux_ctx = NULL;
+ c->mux_pause = 0;
c->delayed = 1; /* prevent call to channel_post handler */
TAILQ_INIT(&c->status_confirms);
debug("channel %d: new [%s]", found, remote_name);
@@ -703,7 +704,7 @@ channel_register_status_confirm(int id, channel_confirm_cb *cb,
}
void
-channel_register_open_confirm(int id, channel_callback_fn *fn, void *ctx)
+channel_register_open_confirm(int id, channel_open_fn *fn, void *ctx)
{
Channel *c = channel_lookup(id);
@@ -838,8 +839,9 @@ channel_pre_open(Channel *c, fd_set *readset, fd_set *writeset)
if (c->extended_usage == CHAN_EXTENDED_WRITE &&
buffer_len(&c->extended) > 0)
FD_SET(c->efd, writeset);
- else if (!(c->flags & CHAN_EOF_SENT) &&
- c->extended_usage == CHAN_EXTENDED_READ &&
+ else if (c->efd != -1 && !(c->flags & CHAN_EOF_SENT) &&
+ (c->extended_usage == CHAN_EXTENDED_READ ||
+ c->extended_usage == CHAN_EXTENDED_IGNORE) &&
buffer_len(&c->extended) < c->remote_window)
FD_SET(c->efd, readset);
}
@@ -915,7 +917,7 @@ x11_open_helper(Buffer *b)
}
/* Check if authentication data matches our fake data. */
if (data_len != x11_fake_data_len ||
- memcmp(ucp + 12 + ((proto_len + 3) & ~3),
+ timingsafe_bcmp(ucp + 12 + ((proto_len + 3) & ~3),
x11_fake_data, x11_fake_data_len) != 0) {
debug2("X11 auth data does not match fake data.");
return -1;
@@ -991,7 +993,7 @@ channel_pre_x11_open(Channel *c, fd_set *readset, fd_set *writeset)
static void
channel_pre_mux_client(Channel *c, fd_set *readset, fd_set *writeset)
{
- if (c->istate == CHAN_INPUT_OPEN &&
+ if (c->istate == CHAN_INPUT_OPEN && !c->mux_pause &&
buffer_check_alloc(&c->input, CHAN_RBUF))
FD_SET(c->rfd, readset);
if (c->istate == CHAN_INPUT_WAIT_DRAIN) {
@@ -1642,13 +1644,14 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
{
struct termios tio;
u_char *data = NULL, *buf;
- u_int dlen;
+ u_int dlen, olen = 0;
int len;
/* Send buffered output data to the socket. */
if (c->wfd != -1 &&
FD_ISSET(c->wfd, writeset) &&
buffer_len(&c->output) > 0) {
+ olen = buffer_len(&c->output);
if (c->output_filter != NULL) {
if ((buf = c->output_filter(c, &data, &dlen)) == NULL) {
debug2("channel %d: filter stops", c->self);
@@ -1667,7 +1670,6 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
if (c->datagram) {
/* ignore truncated writes, datagrams might get lost */
- c->local_consumed += dlen + 4;
len = write(c->wfd, buf, dlen);
xfree(data);
if (len < 0 && (errno == EINTR || errno == EAGAIN ||
@@ -1680,7 +1682,7 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
chan_write_failed(c);
return -1;
}
- return 1;
+ goto out;
}
#ifdef _AIX
/* XXX: Later AIX versions can't push as much data to tty */
@@ -1722,10 +1724,10 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
}
#endif
buffer_consume(&c->output, len);
- if (compat20 && len > 0) {
- c->local_consumed += len;
- }
}
+ out:
+ if (compat20 && olen > 0)
+ c->local_consumed += olen - buffer_len(&c->output);
return 1;
}
@@ -1755,7 +1757,9 @@ channel_handle_efd(Channel *c, fd_set *readset, fd_set *writeset)
buffer_consume(&c->extended, len);
c->local_consumed += len;
}
- } else if (c->extended_usage == CHAN_EXTENDED_READ &&
+ } else if (c->efd != -1 &&
+ (c->extended_usage == CHAN_EXTENDED_READ ||
+ c->extended_usage == CHAN_EXTENDED_IGNORE) &&
(c->detach_close || FD_ISSET(c->efd, readset))) {
len = read(c->efd, buf, sizeof(buf));
debug2("channel %d: read %d from efd %d",
@@ -1768,7 +1772,11 @@ channel_handle_efd(Channel *c, fd_set *readset, fd_set *writeset)
c->self, c->efd);
channel_close_fd(&c->efd);
} else {
- buffer_append(&c->extended, buf, len);
+ if (c->extended_usage == CHAN_EXTENDED_IGNORE) {
+ debug3("channel %d: discard efd",
+ c->self);
+ } else
+ buffer_append(&c->extended, buf, len);
}
}
}
@@ -1840,7 +1848,7 @@ channel_post_mux_client(Channel *c, fd_set *readset, fd_set *writeset)
if (!compat20)
fatal("%s: entered with !compat20", __func__);
- if (c->rfd != -1 && FD_ISSET(c->rfd, readset) &&
+ if (c->rfd != -1 && !c->mux_pause && FD_ISSET(c->rfd, readset) &&
(c->istate == CHAN_INPUT_OPEN ||
c->istate == CHAN_INPUT_WAIT_DRAIN)) {
/*
@@ -2164,6 +2172,14 @@ channel_output_poll(void)
data = buffer_get_string(&c->input,
&dlen);
+ if (dlen > c->remote_window ||
+ dlen > c->remote_maxpacket) {
+ debug("channel %d: datagram "
+ "too big for channel",
+ c->self);
+ xfree(data);
+ continue;
+ }
packet_start(SSH2_MSG_CHANNEL_DATA);
packet_put_int(c->remote_id);
packet_put_string(data, dlen);
@@ -2249,7 +2265,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
{
int id;
char *data;
- u_int data_len;
+ u_int data_len, win_len;
Channel *c;
/* Get the channel number and verify it. */
@@ -2265,6 +2281,9 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
/* Get the data. */
data = packet_get_string_ptr(&data_len);
+ win_len = data_len;
+ if (c->datagram)
+ win_len += 4; /* string length header */
/*
* Ignore data for protocol > 1.3 if output end is no longer open.
@@ -2275,23 +2294,23 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
*/
if (!compat13 && c->ostate != CHAN_OUTPUT_OPEN) {
if (compat20) {
- c->local_window -= data_len;
- c->local_consumed += data_len;
+ c->local_window -= win_len;
+ c->local_consumed += win_len;
}
return;
}
if (compat20) {
- if (data_len > c->local_maxpacket) {
+ if (win_len > c->local_maxpacket) {
logit("channel %d: rcvd big packet %d, maxpack %d",
- c->self, data_len, c->local_maxpacket);
+ c->self, win_len, c->local_maxpacket);
}
- if (data_len > c->local_window) {
+ if (win_len > c->local_window) {
logit("channel %d: rcvd too much data %d, win %d",
- c->self, data_len, c->local_window);
+ c->self, win_len, c->local_window);
return;
}
- c->local_window -= data_len;
+ c->local_window -= win_len;
}
if (c->datagram)
buffer_put_string(&c->output, data, data_len);
@@ -2463,7 +2482,7 @@ channel_input_open_confirmation(int type, u_int32_t seq, void *ctxt)
c->remote_maxpacket = packet_get_int();
if (c->open_confirm) {
debug2("callback start");
- c->open_confirm(c->self, c->open_confirm_ctx);
+ c->open_confirm(c->self, 1, c->open_confirm_ctx);
debug2("callback done");
}
debug2("channel %d: open confirm rwindow %u rmax %u", c->self,
@@ -2514,6 +2533,11 @@ channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
xfree(msg);
if (lang != NULL)
xfree(lang);
+ if (c->open_confirm) {
+ debug2("callback start");
+ c->open_confirm(c->self, 0, c->open_confirm_ctx);
+ debug2("callback done");
+ }
}
packet_check_eom();
/* Schedule the channel for cleanup/deletion. */
@@ -2832,10 +2856,6 @@ channel_request_remote_forwarding(const char *listen_host, u_short listen_port,
{
int type, success = 0;
- /* Record locally that connection to this host/port is permitted. */
- if (num_permitted_opens >= SSH_MAX_FORWARDS_PER_DIRECTION)
- fatal("channel_request_remote_forwarding: too many forwards");
-
/* Send the forward request to the remote side. */
if (compat20) {
const char *address_to_bind;
@@ -2885,6 +2905,9 @@ channel_request_remote_forwarding(const char *listen_host, u_short listen_port,
}
}
if (success) {
+ /* Record that connection to this host/port is permitted. */
+ permitted_opens = xrealloc(permitted_opens,
+ num_permitted_opens + 1, sizeof(*permitted_opens));
permitted_opens[num_permitted_opens].host_to_connect = xstrdup(host_to_connect);
permitted_opens[num_permitted_opens].port_to_connect = port_to_connect;
permitted_opens[num_permitted_opens].listen_port = listen_port;
@@ -2982,10 +3005,10 @@ channel_permit_all_opens(void)
void
channel_add_permitted_opens(char *host, int port)
{
- if (num_permitted_opens >= SSH_MAX_FORWARDS_PER_DIRECTION)
- fatal("channel_add_permitted_opens: too many forwards");
debug("allow port forwarding to host %s port %d", host, port);
+ permitted_opens = xrealloc(permitted_opens,
+ num_permitted_opens + 1, sizeof(*permitted_opens));
permitted_opens[num_permitted_opens].host_to_connect = xstrdup(host);
permitted_opens[num_permitted_opens].port_to_connect = port;
num_permitted_opens++;
@@ -2996,10 +3019,10 @@ channel_add_permitted_opens(char *host, int port)
int
channel_add_adm_permitted_opens(char *host, int port)
{
- if (num_adm_permitted_opens >= SSH_MAX_FORWARDS_PER_DIRECTION)
- fatal("channel_add_adm_permitted_opens: too many forwards");
debug("config allows port forwarding to host %s port %d", host, port);
+ permitted_adm_opens = xrealloc(permitted_adm_opens,
+ num_adm_permitted_opens + 1, sizeof(*permitted_adm_opens));
permitted_adm_opens[num_adm_permitted_opens].host_to_connect
= xstrdup(host);
permitted_adm_opens[num_adm_permitted_opens].port_to_connect = port;
@@ -3014,6 +3037,10 @@ channel_clear_permitted_opens(void)
for (i = 0; i < num_permitted_opens; i++)
if (permitted_opens[i].host_to_connect != NULL)
xfree(permitted_opens[i].host_to_connect);
+ if (num_permitted_opens > 0) {
+ xfree(permitted_opens);
+ permitted_opens = NULL;
+ }
num_permitted_opens = 0;
}
@@ -3025,6 +3052,10 @@ channel_clear_adm_permitted_opens(void)
for (i = 0; i < num_adm_permitted_opens; i++)
if (permitted_adm_opens[i].host_to_connect != NULL)
xfree(permitted_adm_opens[i].host_to_connect);
+ if (num_adm_permitted_opens > 0) {
+ xfree(permitted_adm_opens);
+ permitted_adm_opens = NULL;
+ }
num_adm_permitted_opens = 0;
}
diff --git a/crypto/openssh/channels.h b/crypto/openssh/channels.h
index cc71885..0680ed0 100644
--- a/crypto/openssh/channels.h
+++ b/crypto/openssh/channels.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.h,v 1.103 2010/01/26 01:28:35 djm Exp $ */
+/* $OpenBSD: channels.h,v 1.104 2010/05/14 23:29:23 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -60,6 +60,7 @@
struct Channel;
typedef struct Channel Channel;
+typedef void channel_open_fn(int, int, void *);
typedef void channel_callback_fn(int, void *);
typedef int channel_infilter_fn(struct Channel *, char *, int);
typedef void channel_filter_cleanup_fn(int, void *);
@@ -130,7 +131,7 @@ struct Channel {
char *ctype; /* type */
/* callback */
- channel_callback_fn *open_confirm;
+ channel_open_fn *open_confirm;
void *open_confirm_ctx;
channel_callback_fn *detach_user;
int detach_close;
@@ -151,6 +152,7 @@ struct Channel {
/* multiplexing protocol hook, called for each packet received */
mux_callback_fn *mux_rcb;
void *mux_ctx;
+ int mux_pause;
};
#define CHAN_EXTENDED_IGNORE 0
@@ -208,7 +210,7 @@ void channel_stop_listening(void);
void channel_send_open(int);
void channel_request_start(int, char *, int);
void channel_register_cleanup(int, channel_callback_fn *, int);
-void channel_register_open_confirm(int, channel_callback_fn *, void *);
+void channel_register_open_confirm(int, channel_open_fn *, void *);
void channel_register_filter(int, channel_infilter_fn *,
channel_outfilter_fn *, channel_filter_cleanup_fn *, void *);
void channel_register_status_confirm(int, channel_confirm_cb *,
diff --git a/crypto/openssh/clientloop.c b/crypto/openssh/clientloop.c
index 9ab56b4..de79793 100644
--- a/crypto/openssh/clientloop.c
+++ b/crypto/openssh/clientloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.219 2010/03/13 21:10:38 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.222 2010/07/19 09:15:12 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -145,6 +145,9 @@ static volatile sig_atomic_t received_signal = 0;
/* Flag indicating whether the user's terminal is in non-blocking mode. */
static int in_non_blocking_mode = 0;
+/* Time when backgrounded control master using ControlPersist should exit */
+static time_t control_persist_exit_time = 0;
+
/* Common data for the client loop code. */
volatile sig_atomic_t quit_pending; /* Set non-zero to quit the loop. */
static int escape_char1; /* Escape character. (proto1 only) */
@@ -155,11 +158,12 @@ static int stdin_eof; /* EOF has been encountered on stderr. */
static Buffer stdin_buffer; /* Buffer for stdin data. */
static Buffer stdout_buffer; /* Buffer for stdout data. */
static Buffer stderr_buffer; /* Buffer for stderr data. */
-static u_int buffer_high;/* Soft max buffer size. */
+static u_int buffer_high; /* Soft max buffer size. */
static int connection_in; /* Connection to server (input). */
static int connection_out; /* Connection to server (output). */
static int need_rekeying; /* Set to non-zero if rekeying is requested. */
-static int session_closed = 0; /* In SSH2: login session closed. */
+static int session_closed; /* In SSH2: login session closed. */
+static int x11_refuse_time; /* If >0, refuse x11 opens after this time. */
static void client_init_dispatch(void);
int session_ident = -1;
@@ -251,10 +255,38 @@ get_current_time(void)
return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
}
+/*
+ * Sets control_persist_exit_time to the absolute time when the
+ * backgrounded control master should exit due to expiry of the
+ * ControlPersist timeout. Sets it to 0 if we are not a backgrounded
+ * control master process, or if there is no ControlPersist timeout.
+ */
+static void
+set_control_persist_exit_time(void)
+{
+ if (muxserver_sock == -1 || !options.control_persist
+ || options.control_persist_timeout == 0)
+ /* not using a ControlPersist timeout */
+ control_persist_exit_time = 0;
+ else if (channel_still_open()) {
+ /* some client connections are still open */
+ if (control_persist_exit_time > 0)
+ debug2("%s: cancel scheduled exit", __func__);
+ control_persist_exit_time = 0;
+ } else if (control_persist_exit_time <= 0) {
+ /* a client connection has recently closed */
+ control_persist_exit_time = time(NULL) +
+ (time_t)options.control_persist_timeout;
+ debug2("%s: schedule exit in %d seconds", __func__,
+ options.control_persist_timeout);
+ }
+ /* else we are already counting down to the timeout */
+}
+
#define SSH_X11_PROTO "MIT-MAGIC-COOKIE-1"
void
client_x11_get_proto(const char *display, const char *xauth_path,
- u_int trusted, char **_proto, char **_data)
+ u_int trusted, u_int timeout, char **_proto, char **_data)
{
char cmd[1024];
char line[512];
@@ -264,6 +296,7 @@ client_x11_get_proto(const char *display, const char *xauth_path,
int got_data = 0, generated = 0, do_unlink = 0, i;
char *xauthdir, *xauthfile;
struct stat st;
+ u_int now;
xauthdir = xauthfile = NULL;
*_proto = proto;
@@ -299,11 +332,18 @@ client_x11_get_proto(const char *display, const char *xauth_path,
xauthdir);
snprintf(cmd, sizeof(cmd),
"%s -f %s generate %s " SSH_X11_PROTO
- " untrusted timeout 1200 2>" _PATH_DEVNULL,
- xauth_path, xauthfile, display);
+ " untrusted timeout %u 2>" _PATH_DEVNULL,
+ xauth_path, xauthfile, display, timeout);
debug2("x11_get_proto: %s", cmd);
if (system(cmd) == 0)
generated = 1;
+ if (x11_refuse_time == 0) {
+ now = time(NULL) + 1;
+ if (UINT_MAX - timeout < now)
+ x11_refuse_time = UINT_MAX;
+ else
+ x11_refuse_time = now + timeout;
+ }
}
}
@@ -524,6 +564,7 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
int *maxfdp, u_int *nallocp, int rekeying)
{
struct timeval tv, *tvp;
+ int timeout_secs;
int ret;
/* Add any selections by the channel mechanism. */
@@ -567,16 +608,27 @@ client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp,
/*
* Wait for something to happen. This will suspend the process until
* some selected descriptor can be read, written, or has some other
- * event pending.
+ * event pending, or a timeout expires.
*/
- if (options.server_alive_interval == 0 || !compat20)
+ timeout_secs = INT_MAX; /* we use INT_MAX to mean no timeout */
+ if (options.server_alive_interval > 0 && compat20)
+ timeout_secs = options.server_alive_interval;
+ set_control_persist_exit_time();
+ if (control_persist_exit_time > 0) {
+ timeout_secs = MIN(timeout_secs,
+ control_persist_exit_time - time(NULL));
+ if (timeout_secs < 0)
+ timeout_secs = 0;
+ }
+ if (timeout_secs == INT_MAX)
tvp = NULL;
else {
- tv.tv_sec = options.server_alive_interval;
+ tv.tv_sec = timeout_secs;
tv.tv_usec = 0;
tvp = &tv;
}
+
ret = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp);
if (ret < 0) {
char buf[100];
@@ -1469,6 +1521,18 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
*/
if (FD_ISSET(connection_out, writeset))
packet_write_poll();
+
+ /*
+ * If we are a backgrounded control master, and the
+ * timeout has expired without any active client
+ * connections, then quit.
+ */
+ if (control_persist_exit_time > 0) {
+ if (time(NULL) >= control_persist_exit_time) {
+ debug("ControlPersist timeout expired");
+ break;
+ }
+ }
}
if (readset)
xfree(readset);
@@ -1686,6 +1750,11 @@ client_request_x11(const char *request_type, int rchan)
"malicious server.");
return NULL;
}
+ if (x11_refuse_time != 0 && time(NULL) >= x11_refuse_time) {
+ verbose("Rejected X11 connection after ForwardX11Timeout "
+ "expired");
+ return NULL;
+ }
originator = packet_get_string(NULL);
if (datafellows & SSH_BUG_X11FWD) {
debug2("buggy server: x11 request w/o originator_port");
@@ -1912,7 +1981,7 @@ client_session2_setup(int id, int want_tty, int want_subsystem,
memset(&ws, 0, sizeof(ws));
channel_request_start(id, "pty-req", 1);
- client_expect_confirm(id, "PTY allocation", 0);
+ client_expect_confirm(id, "PTY allocation", 1);
packet_put_cstring(term != NULL ? term : "");
packet_put_int((u_int)ws.ws_col);
packet_put_int((u_int)ws.ws_row);
diff --git a/crypto/openssh/clientloop.h b/crypto/openssh/clientloop.h
index 0b8257b..52115db 100644
--- a/crypto/openssh/clientloop.h
+++ b/crypto/openssh/clientloop.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.h,v 1.23 2010/01/26 01:28:35 djm Exp $ */
+/* $OpenBSD: clientloop.h,v 1.25 2010/06/25 23:15:36 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -39,7 +39,7 @@
/* Client side main loop for the interactive session. */
int client_loop(int, int, int);
-void client_x11_get_proto(const char *, const char *, u_int,
+void client_x11_get_proto(const char *, const char *, u_int, u_int,
char **, char **);
void client_global_request_reply_fwd(int, u_int32_t, void *);
void client_session2_setup(int, int, int, const char *, struct termios *,
@@ -63,6 +63,7 @@ void client_register_global_confirm(global_confirm_cb *, void *);
#define SSHMUX_COMMAND_ALIVE_CHECK 2 /* Check master is alive */
#define SSHMUX_COMMAND_TERMINATE 3 /* Ask master to exit */
#define SSHMUX_COMMAND_STDIO_FWD 4 /* Open stdio fwd (ssh -W) */
+#define SSHMUX_COMMAND_FORWARD 5 /* Forward only, no command */
void muxserver_listen(void);
void muxclient(const char *);
diff --git a/crypto/openssh/config.h b/crypto/openssh/config.h
index 01fc523..c89920b 100644
--- a/crypto/openssh/config.h
+++ b/crypto/openssh/config.h
@@ -904,6 +904,9 @@
/* Define to 1 if you have the `strnvis' function. */
/* #undef HAVE_STRNVIS */
+/* Define to 1 if you have the `strptime' function. */
+#define HAVE_STRPTIME 1
+
/* Define to 1 if you have the `strsep' function. */
#define HAVE_STRSEP 1
diff --git a/crypto/openssh/config.h.in b/crypto/openssh/config.h.in
index a43ad57..4ff407f 100644
--- a/crypto/openssh/config.h.in
+++ b/crypto/openssh/config.h.in
@@ -900,6 +900,9 @@
/* Define to 1 if you have the `strnvis' function. */
#undef HAVE_STRNVIS
+/* Define to 1 if you have the `strptime' function. */
+#undef HAVE_STRPTIME
+
/* Define to 1 if you have the `strsep' function. */
#undef HAVE_STRSEP
diff --git a/crypto/openssh/jpake.c b/crypto/openssh/jpake.c
index 1306610..cdf65f5 100644
--- a/crypto/openssh/jpake.c
+++ b/crypto/openssh/jpake.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jpake.c,v 1.2 2009/03/05 07:18:19 djm Exp $ */
+/* $OpenBSD: jpake.c,v 1.4 2010/07/13 23:13:16 djm Exp $ */
/*
* Copyright (c) 2008 Damien Miller. All rights reserved.
*
@@ -434,7 +434,7 @@ jpake_check_confirm(const BIGNUM *k,
if (peer_confirm_hash_len != expected_confirm_hash_len)
error("%s: confirmation length mismatch (my %u them %u)",
__func__, expected_confirm_hash_len, peer_confirm_hash_len);
- else if (memcmp(peer_confirm_hash, expected_confirm_hash,
+ else if (timingsafe_bcmp(peer_confirm_hash, expected_confirm_hash,
expected_confirm_hash_len) == 0)
success = 1;
bzero(expected_confirm_hash, expected_confirm_hash_len);
diff --git a/crypto/openssh/key.c b/crypto/openssh/key.c
index 66592c7..e4aa25c 100644
--- a/crypto/openssh/key.c
+++ b/crypto/openssh/key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key.c,v 1.86 2010/03/15 19:40:02 stevesk Exp $ */
+/* $OpenBSD: key.c,v 1.90 2010/07/13 23:13:16 djm Exp $ */
/*
* read_bignum():
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -52,6 +52,7 @@
#include "uuencode.h"
#include "buffer.h"
#include "log.h"
+#include "misc.h"
#include "ssh2.h"
static struct KeyCert *
@@ -61,7 +62,8 @@ cert_new(void)
cert = xcalloc(1, sizeof(*cert));
buffer_init(&cert->certblob);
- buffer_init(&cert->constraints);
+ buffer_init(&cert->critical);
+ buffer_init(&cert->extensions);
cert->key_id = NULL;
cert->principals = NULL;
cert->signature_key = NULL;
@@ -82,6 +84,7 @@ key_new(int type)
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
if ((rsa = RSA_new()) == NULL)
fatal("key_new: RSA_new failed");
@@ -92,6 +95,7 @@ key_new(int type)
k->rsa = rsa;
break;
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
if ((dsa = DSA_new()) == NULL)
fatal("key_new: DSA_new failed");
@@ -124,6 +128,7 @@ key_add_private(Key *k)
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
if ((k->rsa->d = BN_new()) == NULL)
fatal("key_new_private: BN_new failed");
@@ -139,6 +144,7 @@ key_add_private(Key *k)
fatal("key_new_private: BN_new failed");
break;
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
if ((k->dsa->priv_key = BN_new()) == NULL)
fatal("key_new_private: BN_new failed");
@@ -165,7 +171,8 @@ cert_free(struct KeyCert *cert)
u_int i;
buffer_free(&cert->certblob);
- buffer_free(&cert->constraints);
+ buffer_free(&cert->critical);
+ buffer_free(&cert->extensions);
if (cert->key_id != NULL)
xfree(cert->key_id);
for (i = 0; i < cert->nprincipals; i++)
@@ -184,12 +191,14 @@ key_free(Key *k)
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
if (k->rsa != NULL)
RSA_free(k->rsa);
k->rsa = NULL;
break;
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
if (k->dsa != NULL)
DSA_free(k->dsa);
@@ -219,7 +228,7 @@ cert_compare(struct KeyCert *a, struct KeyCert *b)
return 0;
if (buffer_len(&a->certblob) != buffer_len(&b->certblob))
return 0;
- if (memcmp(buffer_ptr(&a->certblob), buffer_ptr(&b->certblob),
+ if (timingsafe_bcmp(buffer_ptr(&a->certblob), buffer_ptr(&b->certblob),
buffer_len(&a->certblob)) != 0)
return 0;
return 1;
@@ -238,11 +247,13 @@ key_equal_public(const Key *a, const Key *b)
switch (a->type) {
case KEY_RSA1:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_RSA:
return a->rsa != NULL && b->rsa != NULL &&
BN_cmp(a->rsa->e, b->rsa->e) == 0 &&
BN_cmp(a->rsa->n, b->rsa->n) == 0;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_DSA:
return a->dsa != NULL && b->dsa != NULL &&
@@ -304,6 +315,8 @@ key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
case KEY_RSA:
key_to_blob(k, &blob, &len);
break;
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_RSA_CERT:
/* We want a fingerprint of the _key_ not of the cert */
@@ -631,6 +644,8 @@ key_read(Key *ret, char **cpp)
case KEY_UNSPEC:
case KEY_RSA:
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_RSA_CERT:
space = strchr(cp, ' ');
@@ -757,11 +772,13 @@ key_write(const Key *key, FILE *f)
error("key_write: failed for RSA key");
return 0;
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
if (key->dsa == NULL)
return 0;
break;
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
if (key->rsa == NULL)
return 0;
@@ -793,6 +810,10 @@ key_type(const Key *k)
return "RSA";
case KEY_DSA:
return "DSA";
+ case KEY_RSA_CERT_V00:
+ return "RSA-CERT-V00";
+ case KEY_DSA_CERT_V00:
+ return "DSA-CERT-V00";
case KEY_RSA_CERT:
return "RSA-CERT";
case KEY_DSA_CERT:
@@ -822,10 +843,14 @@ key_ssh_name(const Key *k)
return "ssh-rsa";
case KEY_DSA:
return "ssh-dss";
- case KEY_RSA_CERT:
+ case KEY_RSA_CERT_V00:
return "ssh-rsa-cert-v00@openssh.com";
- case KEY_DSA_CERT:
+ case KEY_DSA_CERT_V00:
return "ssh-dss-cert-v00@openssh.com";
+ case KEY_RSA_CERT:
+ return "ssh-rsa-cert-v01@openssh.com";
+ case KEY_DSA_CERT:
+ return "ssh-dss-cert-v01@openssh.com";
}
return "ssh-unknown";
}
@@ -836,9 +861,11 @@ key_size(const Key *k)
switch (k->type) {
case KEY_RSA1:
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
return BN_num_bits(k->rsa->n);
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
return BN_num_bits(k->dsa->p);
}
@@ -882,6 +909,8 @@ key_generate(int type, u_int bits)
case KEY_RSA1:
k->rsa = rsa_generate_private_key(bits);
break;
+ case KEY_RSA_CERT_V00:
+ case KEY_DSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_DSA_CERT:
fatal("key_generate: cert keys cannot be generated directly");
@@ -912,9 +941,12 @@ key_cert_copy(const Key *from_key, struct Key *to_key)
buffer_append(&to->certblob, buffer_ptr(&from->certblob),
buffer_len(&from->certblob));
- buffer_append(&to->constraints, buffer_ptr(&from->constraints),
- buffer_len(&from->constraints));
+ buffer_append(&to->critical,
+ buffer_ptr(&from->critical), buffer_len(&from->critical));
+ buffer_append(&to->extensions,
+ buffer_ptr(&from->extensions), buffer_len(&from->extensions));
+ to->serial = from->serial;
to->type = from->type;
to->key_id = from->key_id == NULL ? NULL : xstrdup(from->key_id);
to->valid_after = from->valid_after;
@@ -940,6 +972,7 @@ key_from_private(const Key *k)
Key *n = NULL;
switch (k->type) {
case KEY_DSA:
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
n = key_new(k->type);
if ((BN_copy(n->dsa->p, k->dsa->p) == NULL) ||
@@ -950,6 +983,7 @@ key_from_private(const Key *k)
break;
case KEY_RSA:
case KEY_RSA1:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
n = key_new(k->type);
if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
@@ -979,8 +1013,12 @@ key_type_from_name(char *name)
} else if (strcmp(name, "ssh-dss") == 0) {
return KEY_DSA;
} else if (strcmp(name, "ssh-rsa-cert-v00@openssh.com") == 0) {
- return KEY_RSA_CERT;
+ return KEY_RSA_CERT_V00;
} else if (strcmp(name, "ssh-dss-cert-v00@openssh.com") == 0) {
+ return KEY_DSA_CERT_V00;
+ } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
+ return KEY_RSA_CERT;
+ } else if (strcmp(name, "ssh-dss-cert-v01@openssh.com") == 0) {
return KEY_DSA_CERT;
}
debug2("key_type_from_name: unknown key type '%s'", name);
@@ -1012,26 +1050,31 @@ key_names_valid2(const char *names)
static int
cert_parse(Buffer *b, Key *key, const u_char *blob, u_int blen)
{
- u_char *principals, *constraints, *sig_key, *sig;
- u_int signed_len, plen, clen, sklen, slen, kidlen;
+ u_char *principals, *critical, *exts, *sig_key, *sig;
+ u_int signed_len, plen, clen, sklen, slen, kidlen, elen;
Buffer tmp;
char *principal;
int ret = -1;
+ int v00 = key->type == KEY_DSA_CERT_V00 ||
+ key->type == KEY_RSA_CERT_V00;
buffer_init(&tmp);
/* Copy the entire key blob for verification and later serialisation */
buffer_append(&key->cert->certblob, blob, blen);
- principals = constraints = sig_key = sig = NULL;
- if (buffer_get_int_ret(&key->cert->type, b) != 0 ||
+ elen = 0; /* Not touched for v00 certs */
+ principals = exts = critical = sig_key = sig = NULL;
+ if ((!v00 && buffer_get_int64_ret(&key->cert->serial, b) != 0) ||
+ buffer_get_int_ret(&key->cert->type, b) != 0 ||
(key->cert->key_id = buffer_get_string_ret(b, &kidlen)) == NULL ||
(principals = buffer_get_string_ret(b, &plen)) == NULL ||
buffer_get_int64_ret(&key->cert->valid_after, b) != 0 ||
buffer_get_int64_ret(&key->cert->valid_before, b) != 0 ||
- (constraints = buffer_get_string_ret(b, &clen)) == NULL ||
- /* skip nonce */ buffer_get_string_ptr_ret(b, NULL) == NULL ||
- /* skip reserved */ buffer_get_string_ptr_ret(b, NULL) == NULL ||
+ (critical = buffer_get_string_ret(b, &clen)) == NULL ||
+ (!v00 && (exts = buffer_get_string_ret(b, &elen)) == NULL) ||
+ (v00 && buffer_get_string_ptr_ret(b, NULL) == NULL) || /* nonce */
+ buffer_get_string_ptr_ret(b, NULL) == NULL || /* reserved */
(sig_key = buffer_get_string_ret(b, &sklen)) == NULL) {
error("%s: parse error", __func__);
goto out;
@@ -1078,13 +1121,25 @@ cert_parse(Buffer *b, Key *key, const u_char *blob, u_int blen)
buffer_clear(&tmp);
- buffer_append(&key->cert->constraints, constraints, clen);
- buffer_append(&tmp, constraints, clen);
+ buffer_append(&key->cert->critical, critical, clen);
+ buffer_append(&tmp, critical, clen);
/* validate structure */
while (buffer_len(&tmp) != 0) {
if (buffer_get_string_ptr_ret(&tmp, NULL) == NULL ||
buffer_get_string_ptr_ret(&tmp, NULL) == NULL) {
- error("%s: Constraints data invalid", __func__);
+ error("%s: critical option data invalid", __func__);
+ goto out;
+ }
+ }
+ buffer_clear(&tmp);
+
+ buffer_append(&key->cert->extensions, exts, elen);
+ buffer_append(&tmp, exts, elen);
+ /* validate structure */
+ while (buffer_len(&tmp) != 0) {
+ if (buffer_get_string_ptr_ret(&tmp, NULL) == NULL ||
+ buffer_get_string_ptr_ret(&tmp, NULL) == NULL) {
+ error("%s: extension data invalid", __func__);
goto out;
}
}
@@ -1121,8 +1176,10 @@ cert_parse(Buffer *b, Key *key, const u_char *blob, u_int blen)
buffer_free(&tmp);
if (principals != NULL)
xfree(principals);
- if (constraints != NULL)
- xfree(constraints);
+ if (critical != NULL)
+ xfree(critical);
+ if (exts != NULL)
+ xfree(exts);
if (sig_key != NULL)
xfree(sig_key);
if (sig != NULL)
@@ -1151,8 +1208,11 @@ key_from_blob(const u_char *blob, u_int blen)
type = key_type_from_name(ktype);
switch (type) {
- case KEY_RSA:
case KEY_RSA_CERT:
+ (void)buffer_get_string_ptr_ret(&b, NULL); /* Skip nonce */
+ /* FALLTHROUGH */
+ case KEY_RSA:
+ case KEY_RSA_CERT_V00:
key = key_new(type);
if (buffer_get_bignum2_ret(&b, key->rsa->e) == -1 ||
buffer_get_bignum2_ret(&b, key->rsa->n) == -1) {
@@ -1166,8 +1226,11 @@ key_from_blob(const u_char *blob, u_int blen)
RSA_print_fp(stderr, key->rsa, 8);
#endif
break;
- case KEY_DSA:
case KEY_DSA_CERT:
+ (void)buffer_get_string_ptr_ret(&b, NULL); /* Skip nonce */
+ /* FALLTHROUGH */
+ case KEY_DSA:
+ case KEY_DSA_CERT_V00:
key = key_new(type);
if (buffer_get_bignum2_ret(&b, key->dsa->p) == -1 ||
buffer_get_bignum2_ret(&b, key->dsa->q) == -1 ||
@@ -1213,6 +1276,8 @@ key_to_blob(const Key *key, u_char **blobp, u_int *lenp)
}
buffer_init(&b);
switch (key->type) {
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_RSA_CERT:
/* Use the existing blob */
@@ -1255,9 +1320,11 @@ key_sign(
const u_char *data, u_int datalen)
{
switch (key->type) {
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_DSA:
return ssh_dss_sign(key, sigp, lenp, data, datalen);
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_RSA:
return ssh_rsa_sign(key, sigp, lenp, data, datalen);
@@ -1281,9 +1348,11 @@ key_verify(
return -1;
switch (key->type) {
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
case KEY_DSA:
return ssh_dss_verify(key, signature, signaturelen, data, datalen);
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_RSA:
return ssh_rsa_verify(key, signature, signaturelen, data, datalen);
@@ -1306,6 +1375,7 @@ key_demote(const Key *k)
pk->rsa = NULL;
switch (k->type) {
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
key_cert_copy(k, pk);
/* FALLTHROUGH */
@@ -1318,6 +1388,7 @@ key_demote(const Key *k)
if ((pk->rsa->n = BN_dup(k->rsa->n)) == NULL)
fatal("key_demote: BN_dup failed");
break;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
key_cert_copy(k, pk);
/* FALLTHROUGH */
@@ -1344,8 +1415,17 @@ key_demote(const Key *k)
int
key_is_cert(const Key *k)
{
- return k != NULL &&
- (k->type == KEY_RSA_CERT || k->type == KEY_DSA_CERT);
+ if (k == NULL)
+ return 0;
+ switch (k->type) {
+ case KEY_RSA_CERT_V00:
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT:
+ case KEY_DSA_CERT:
+ return 1;
+ default:
+ return 0;
+ }
}
/* Return the cert-less equivalent to a certified key type */
@@ -1353,8 +1433,10 @@ int
key_type_plain(int type)
{
switch (type) {
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
return KEY_RSA;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
return KEY_DSA;
default:
@@ -1364,16 +1446,16 @@ key_type_plain(int type)
/* Convert a KEY_RSA or KEY_DSA to their _CERT equivalent */
int
-key_to_certified(Key *k)
+key_to_certified(Key *k, int legacy)
{
switch (k->type) {
case KEY_RSA:
k->cert = cert_new();
- k->type = KEY_RSA_CERT;
+ k->type = legacy ? KEY_RSA_CERT_V00 : KEY_RSA_CERT;
return 0;
case KEY_DSA:
k->cert = cert_new();
- k->type = KEY_DSA_CERT;
+ k->type = legacy ? KEY_DSA_CERT_V00 : KEY_DSA_CERT;
return 0;
default:
error("%s: key has incorrect type %s", __func__, key_type(k));
@@ -1386,10 +1468,12 @@ int
key_drop_cert(Key *k)
{
switch (k->type) {
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
cert_free(k->cert);
k->type = KEY_RSA;
return 0;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
cert_free(k->cert);
k->type = KEY_DSA;
@@ -1430,13 +1514,21 @@ key_certify(Key *k, Key *ca)
buffer_clear(&k->cert->certblob);
buffer_put_cstring(&k->cert->certblob, key_ssh_name(k));
+ /* -v01 certs put nonce first */
+ if (k->type == KEY_DSA_CERT || k->type == KEY_RSA_CERT) {
+ arc4random_buf(&nonce, sizeof(nonce));
+ buffer_put_string(&k->cert->certblob, nonce, sizeof(nonce));
+ }
+
switch (k->type) {
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
buffer_put_bignum2(&k->cert->certblob, k->dsa->p);
buffer_put_bignum2(&k->cert->certblob, k->dsa->q);
buffer_put_bignum2(&k->cert->certblob, k->dsa->g);
buffer_put_bignum2(&k->cert->certblob, k->dsa->pub_key);
break;
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
buffer_put_bignum2(&k->cert->certblob, k->rsa->e);
buffer_put_bignum2(&k->cert->certblob, k->rsa->n);
@@ -1448,6 +1540,10 @@ key_certify(Key *k, Key *ca)
return -1;
}
+ /* -v01 certs have a serial number next */
+ if (k->type == KEY_DSA_CERT || k->type == KEY_RSA_CERT)
+ buffer_put_int64(&k->cert->certblob, k->cert->serial);
+
buffer_put_int(&k->cert->certblob, k->cert->type);
buffer_put_cstring(&k->cert->certblob, k->cert->key_id);
@@ -1461,11 +1557,19 @@ key_certify(Key *k, Key *ca)
buffer_put_int64(&k->cert->certblob, k->cert->valid_after);
buffer_put_int64(&k->cert->certblob, k->cert->valid_before);
buffer_put_string(&k->cert->certblob,
- buffer_ptr(&k->cert->constraints),
- buffer_len(&k->cert->constraints));
+ buffer_ptr(&k->cert->critical), buffer_len(&k->cert->critical));
+
+ /* -v01 certs have non-critical options here */
+ if (k->type == KEY_DSA_CERT || k->type == KEY_RSA_CERT) {
+ buffer_put_string(&k->cert->certblob,
+ buffer_ptr(&k->cert->extensions),
+ buffer_len(&k->cert->extensions));
+ }
+
+ /* -v00 certs put the nonce at the end */
+ if (k->type == KEY_DSA_CERT_V00 || k->type == KEY_RSA_CERT_V00)
+ buffer_put_string(&k->cert->certblob, nonce, sizeof(nonce));
- arc4random_buf(&nonce, sizeof(nonce));
- buffer_put_string(&k->cert->certblob, nonce, sizeof(nonce));
buffer_put_string(&k->cert->certblob, NULL, 0); /* reserved */
buffer_put_string(&k->cert->certblob, ca_blob, ca_len);
xfree(ca_blob);
@@ -1520,7 +1624,7 @@ key_cert_check_authority(const Key *k, int want_host, int require_principal,
*reason = "Certificate lacks principal list";
return -1;
}
- } else {
+ } else if (name != NULL) {
principal_matches = 0;
for (i = 0; i < k->cert->nprincipals; i++) {
if (strcmp(name, k->cert->principals[i]) == 0) {
@@ -1536,3 +1640,15 @@ key_cert_check_authority(const Key *k, int want_host, int require_principal,
}
return 0;
}
+
+int
+key_cert_is_legacy(Key *k)
+{
+ switch (k->type) {
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT_V00:
+ return 1;
+ default:
+ return 0;
+ }
+}
diff --git a/crypto/openssh/key.h b/crypto/openssh/key.h
index 4f17777..11d30ea 100644
--- a/crypto/openssh/key.h
+++ b/crypto/openssh/key.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: key.h,v 1.29 2010/03/15 19:40:02 stevesk Exp $ */
+/* $OpenBSD: key.h,v 1.30 2010/04/16 01:47:26 djm Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -37,6 +37,8 @@ enum types {
KEY_DSA,
KEY_RSA_CERT,
KEY_DSA_CERT,
+ KEY_RSA_CERT_V00,
+ KEY_DSA_CERT_V00,
KEY_UNSPEC
};
enum fp_type {
@@ -56,11 +58,13 @@ enum fp_rep {
struct KeyCert {
Buffer certblob; /* Kept around for use on wire */
u_int type; /* SSH2_CERT_TYPE_USER or SSH2_CERT_TYPE_HOST */
+ u_int64_t serial;
char *key_id;
u_int nprincipals;
char **principals;
u_int64_t valid_after, valid_before;
- Buffer constraints;
+ Buffer critical;
+ Buffer extensions;
Key *signature_key;
};
@@ -92,12 +96,13 @@ Key *key_from_private(const Key *);
int key_type_from_name(char *);
int key_is_cert(const Key *);
int key_type_plain(int);
-int key_to_certified(Key *);
+int key_to_certified(Key *, int);
int key_drop_cert(Key *);
int key_certify(Key *, Key *);
void key_cert_copy(const Key *, struct Key *);
int key_cert_check_authority(const Key *, int, int, const char *,
const char **);
+int key_cert_is_legacy(Key *);
Key *key_from_blob(const u_char *, u_int);
int key_to_blob(const Key *, u_char **, u_int *);
diff --git a/crypto/openssh/loginrec.h b/crypto/openssh/loginrec.h
index 859e1a6..84b4865 100644
--- a/crypto/openssh/loginrec.h
+++ b/crypto/openssh/loginrec.h
@@ -56,7 +56,7 @@ union login_netinfo {
/* string lengths - set very long */
#define LINFO_PROGSIZE 64
#define LINFO_LINESIZE 64
-#define LINFO_NAMESIZE 128
+#define LINFO_NAMESIZE 512
#define LINFO_HOSTSIZE 256
struct logininfo {
diff --git a/crypto/openssh/misc.c b/crypto/openssh/misc.c
index e1f7231..a82e793 100644
--- a/crypto/openssh/misc.c
+++ b/crypto/openssh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.75 2010/01/09 23:04:13 dtucker Exp $ */
+/* $OpenBSD: misc.c,v 1.80 2010/07/21 02:10:58 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -178,6 +178,7 @@ strdelim(char **s)
return (NULL); /* no matching quote */
} else {
*s[0] = '\0';
+ *s += strspn(*s + 1, WHITESPACE) + 1;
return (old);
}
}
@@ -425,7 +426,7 @@ colon(char *cp)
int flag = 0;
if (*cp == ':') /* Leading colon is part of file name. */
- return (0);
+ return NULL;
if (*cp == '[')
flag = 1;
@@ -437,9 +438,9 @@ colon(char *cp)
if (*cp == ':' && !flag)
return (cp);
if (*cp == '/')
- return (0);
+ return NULL;
}
- return (0);
+ return NULL;
}
/* function to assist building execv() arguments */
@@ -849,6 +850,16 @@ ms_to_timeval(struct timeval *tv, int ms)
tv->tv_usec = (ms % 1000) * 1000;
}
+int
+timingsafe_bcmp(const void *b1, const void *b2, size_t n)
+{
+ const unsigned char *p1 = b1, *p2 = b2;
+ int ret = 0;
+
+ for (; n > 0; n--)
+ ret |= *p1++ ^ *p2++;
+ return (ret != 0);
+}
void
sock_set_v6only(int s)
{
diff --git a/crypto/openssh/misc.h b/crypto/openssh/misc.h
index 32073ac..bb799f6 100644
--- a/crypto/openssh/misc.h
+++ b/crypto/openssh/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.41 2010/01/09 23:04:13 dtucker Exp $ */
+/* $OpenBSD: misc.h,v 1.43 2010/07/13 23:13:16 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -36,6 +36,7 @@ void sanitise_stdfd(void);
void ms_subtract_diff(struct timeval *, int *);
void ms_to_timeval(struct timeval *, int);
void sock_set_v6only(int);
+int timingsafe_bcmp(const void *, const void *, size_t);
struct passwd *pwcopy(struct passwd *);
const char *ssh_gai_strerror(int);
diff --git a/crypto/openssh/monitor.c b/crypto/openssh/monitor.c
index 334aedd..9eb4e35 100644
--- a/crypto/openssh/monitor.c
+++ b/crypto/openssh/monitor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: monitor.c,v 1.106 2010/03/07 11:57:13 dtucker Exp $ */
+/* $OpenBSD: monitor.c,v 1.108 2010/07/13 23:13:16 djm Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -518,7 +518,7 @@ monitor_allowed_key(u_char *blob, u_int bloblen)
{
/* make sure key is allowed */
if (key_blob == NULL || key_bloblen != bloblen ||
- memcmp(key_blob, blob, key_bloblen))
+ timingsafe_bcmp(key_blob, blob, key_bloblen))
return (0);
return (1);
}
@@ -922,8 +922,8 @@ mm_answer_pam_init_ctx(int sock, Buffer *m)
int
mm_answer_pam_query(int sock, Buffer *m)
{
- char *name, *info, **prompts;
- u_int i, num, *echo_on;
+ char *name = NULL, *info = NULL, **prompts = NULL;
+ u_int i, num = 0, *echo_on = 0;
int ret;
debug3("%s", __func__);
@@ -1103,14 +1103,14 @@ monitor_valid_userblob(u_char *data, u_int datalen)
len = buffer_len(&b);
if ((session_id2 == NULL) ||
(len < session_id2_len) ||
- (memcmp(p, session_id2, session_id2_len) != 0))
+ (timingsafe_bcmp(p, session_id2, session_id2_len) != 0))
fail++;
buffer_consume(&b, session_id2_len);
} else {
p = buffer_get_string(&b, &len);
if ((session_id2 == NULL) ||
(len != session_id2_len) ||
- (memcmp(p, session_id2, session_id2_len) != 0))
+ (timingsafe_bcmp(p, session_id2, session_id2_len) != 0))
fail++;
xfree(p);
}
@@ -1158,7 +1158,7 @@ monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
p = buffer_get_string(&b, &len);
if ((session_id2 == NULL) ||
(len != session_id2_len) ||
- (memcmp(p, session_id2, session_id2_len) != 0))
+ (timingsafe_bcmp(p, session_id2, session_id2_len) != 0))
fail++;
xfree(p);
@@ -1682,9 +1682,9 @@ mm_get_kex(Buffer *m)
kex = xcalloc(1, sizeof(*kex));
kex->session_id = buffer_get_string(m, &kex->session_id_len);
- if ((session_id2 == NULL) ||
- (kex->session_id_len != session_id2_len) ||
- (memcmp(kex->session_id, session_id2, session_id2_len) != 0))
+ if (session_id2 == NULL ||
+ kex->session_id_len != session_id2_len ||
+ timingsafe_bcmp(kex->session_id, session_id2, session_id2_len) != 0)
fatal("mm_get_get: internal error: bad session id");
kex->we_need = buffer_get_int(m);
kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
diff --git a/crypto/openssh/mux.c b/crypto/openssh/mux.c
index 825fb7a..5c3857e 100644
--- a/crypto/openssh/mux.c
+++ b/crypto/openssh/mux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mux.c,v 1.14 2010/01/30 02:54:53 djm Exp $ */
+/* $OpenBSD: mux.c,v 1.21 2010/06/25 23:15:36 djm Exp $ */
/*
* Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
*
@@ -71,6 +71,7 @@
#include "xmalloc.h"
#include "log.h"
#include "ssh.h"
+#include "ssh2.h"
#include "pathnames.h"
#include "misc.h"
#include "match.h"
@@ -106,6 +107,14 @@ struct mux_session_confirm_ctx {
char *term;
struct termios tio;
char **env;
+ u_int rid;
+};
+
+/* Context for global channel callback */
+struct mux_channel_confirm_ctx {
+ u_int cid; /* channel id */
+ u_int rid; /* request id */
+ int fid; /* forward id */
};
/* fd to control socket */
@@ -143,13 +152,14 @@ struct mux_master_state {
#define MUX_S_EXIT_MESSAGE 0x80000004
#define MUX_S_ALIVE 0x80000005
#define MUX_S_SESSION_OPENED 0x80000006
+#define MUX_S_REMOTE_PORT 0x80000007
/* type codes for MUX_C_OPEN_FWD and MUX_C_CLOSE_FWD */
#define MUX_FWD_LOCAL 1
#define MUX_FWD_REMOTE 2
#define MUX_FWD_DYNAMIC 3
-static void mux_session_confirm(int, void *);
+static void mux_session_confirm(int, int, void *);
static int process_mux_master_hello(u_int, Channel *, Buffer *, Buffer *);
static int process_mux_new_session(u_int, Channel *, Buffer *, Buffer *);
@@ -206,7 +216,7 @@ mux_master_control_cleanup_cb(int cid, void *unused)
fatal("%s: channel_by_id(%i) == NULL", __func__, cid);
if (c->remote_id != -1) {
if ((sc = channel_by_id(c->remote_id)) == NULL)
- debug2("%s: channel %d n session channel %d",
+ fatal("%s: channel %d missing session channel %d",
__func__, c->self, c->remote_id);
c->remote_id = -1;
sc->ctl_chan = -1;
@@ -301,6 +311,7 @@ process_mux_new_session(u_int rid, Channel *c, Buffer *m, Buffer *r)
/* Reply for SSHMUX_COMMAND_OPEN */
cctx = xcalloc(1, sizeof(*cctx));
cctx->term = NULL;
+ cctx->rid = rid;
cmd = reserved = NULL;
if ((reserved = buffer_get_string_ret(m, NULL)) == NULL ||
buffer_get_int_ret(&cctx->want_tty, m) != 0 ||
@@ -454,14 +465,10 @@ process_mux_new_session(u_int rid, Channel *c, Buffer *m, Buffer *r)
channel_send_open(nc->self);
channel_register_open_confirm(nc->self, mux_session_confirm, cctx);
- channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 0);
-
- /* prepare reply */
- /* XXX defer until mux_session_confirm() fires */
- buffer_put_int(r, MUX_S_SESSION_OPENED);
- buffer_put_int(r, rid);
- buffer_put_int(r, nc->self);
+ c->mux_pause = 1; /* stop handling messages until open_confirm done */
+ channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 1);
+ /* reply is deferred, sent by mux_session_confirm */
return 0;
}
@@ -559,6 +566,61 @@ compare_forward(Forward *a, Forward *b)
return 1;
}
+static void
+mux_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
+{
+ struct mux_channel_confirm_ctx *fctx = ctxt;
+ char *failmsg = NULL;
+ Forward *rfwd;
+ Channel *c;
+ Buffer out;
+
+ if ((c = channel_by_id(fctx->cid)) == NULL) {
+ /* no channel for reply */
+ error("%s: unknown channel", __func__);
+ return;
+ }
+ buffer_init(&out);
+ if (fctx->fid >= options.num_remote_forwards) {
+ xasprintf(&failmsg, "unknown forwarding id %d", fctx->fid);
+ goto fail;
+ }
+ rfwd = &options.remote_forwards[fctx->fid];
+ debug("%s: %s for: listen %d, connect %s:%d", __func__,
+ type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure",
+ rfwd->listen_port, rfwd->connect_host, rfwd->connect_port);
+ if (type == SSH2_MSG_REQUEST_SUCCESS) {
+ if (rfwd->listen_port == 0) {
+ rfwd->allocated_port = packet_get_int();
+ logit("Allocated port %u for mux remote forward"
+ " to %s:%d", rfwd->allocated_port,
+ rfwd->connect_host, rfwd->connect_port);
+ buffer_put_int(&out, MUX_S_REMOTE_PORT);
+ buffer_put_int(&out, fctx->rid);
+ buffer_put_int(&out, rfwd->allocated_port);
+ } else {
+ buffer_put_int(&out, MUX_S_OK);
+ buffer_put_int(&out, fctx->rid);
+ }
+ goto out;
+ } else {
+ xasprintf(&failmsg, "remote port forwarding failed for "
+ "listen port %d", rfwd->listen_port);
+ }
+ fail:
+ error("%s: %s", __func__, failmsg);
+ buffer_put_int(&out, MUX_S_FAILURE);
+ buffer_put_int(&out, fctx->rid);
+ buffer_put_cstring(&out, failmsg);
+ xfree(failmsg);
+ out:
+ buffer_put_string(&c->output, buffer_ptr(&out), buffer_len(&out));
+ buffer_free(&out);
+ if (c->mux_pause <= 0)
+ fatal("%s: mux_pause %d", __func__, c->mux_pause);
+ c->mux_pause = 0; /* start processing messages again */
+}
+
static int
process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
{
@@ -594,15 +656,16 @@ process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
ftype != MUX_FWD_DYNAMIC) {
logit("%s: invalid forwarding type %u", __func__, ftype);
invalid:
- xfree(fwd.listen_host);
- xfree(fwd.connect_host);
+ if (fwd.listen_host)
+ xfree(fwd.listen_host);
+ if (fwd.connect_host)
+ xfree(fwd.connect_host);
buffer_put_int(r, MUX_S_FAILURE);
buffer_put_int(r, rid);
buffer_put_cstring(r, "Invalid forwarding request");
return 0;
}
- /* XXX support rport0 forwarding with reply of port assigned */
- if (fwd.listen_port == 0 || fwd.listen_port >= 65536) {
+ if (fwd.listen_port >= 65536) {
logit("%s: invalid listen port %u", __func__,
fwd.listen_port);
goto invalid;
@@ -637,8 +700,17 @@ process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
case MUX_FWD_REMOTE:
for (i = 0; i < options.num_remote_forwards; i++) {
if (compare_forward(&fwd,
- options.remote_forwards + i))
- goto exists;
+ options.remote_forwards + i)) {
+ if (fwd.listen_port != 0)
+ goto exists;
+ debug2("%s: found allocated port",
+ __func__);
+ buffer_put_int(r, MUX_S_REMOTE_PORT);
+ buffer_put_int(r, rid);
+ buffer_put_int(r,
+ options.remote_forwards[i].allocated_port);
+ goto out;
+ }
}
break;
}
@@ -655,9 +727,7 @@ process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
}
if (ftype == MUX_FWD_LOCAL || ftype == MUX_FWD_DYNAMIC) {
- if (options.num_local_forwards + 1 >=
- SSH_MAX_FORWARDS_PER_DIRECTION ||
- channel_setup_local_fwd_listener(fwd.listen_host,
+ if (channel_setup_local_fwd_listener(fwd.listen_host,
fwd.listen_port, fwd.connect_host, fwd.connect_port,
options.gateway_ports) < 0) {
fail:
@@ -670,14 +740,22 @@ process_mux_open_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
add_local_forward(&options, &fwd);
freefwd = 0;
} else {
- /* XXX wait for remote to confirm */
- if (options.num_remote_forwards + 1 >=
- SSH_MAX_FORWARDS_PER_DIRECTION ||
- channel_request_remote_forwarding(fwd.listen_host,
+ struct mux_channel_confirm_ctx *fctx;
+
+ if (channel_request_remote_forwarding(fwd.listen_host,
fwd.listen_port, fwd.connect_host, fwd.connect_port) < 0)
goto fail;
add_remote_forward(&options, &fwd);
+ fctx = xcalloc(1, sizeof(*fctx));
+ fctx->cid = c->self;
+ fctx->rid = rid;
+ fctx->fid = options.num_remote_forwards - 1;
+ client_register_global_confirm(mux_confirm_remote_forward,
+ fctx);
freefwd = 0;
+ c->mux_pause = 1; /* wait for mux_confirm_remote_forward */
+ /* delayed reply in mux_confirm_remote_forward */
+ goto out;
}
buffer_put_int(r, MUX_S_OK);
buffer_put_int(r, rid);
@@ -826,7 +904,7 @@ process_mux_stdio_fwd(u_int rid, Channel *c, Buffer *m, Buffer *r)
debug2("%s: channel_new: %d linked to control channel %d",
__func__, nc->self, nc->ctl_chan);
- channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 0);
+ channel_register_cleanup(nc->self, mux_master_session_cleanup_cb, 1);
/* prepare reply */
/* XXX defer until channel confirmed */
@@ -849,7 +927,7 @@ mux_master_read_cb(Channel *c)
/* Setup ctx and */
if (c->mux_ctx == NULL) {
- state = xcalloc(1, sizeof(state));
+ state = xcalloc(1, sizeof(*state));
c->mux_ctx = state;
channel_register_cleanup(c->self,
mux_master_control_cleanup_cb, 0);
@@ -1000,26 +1078,43 @@ muxserver_listen(void)
/* Callback on open confirmation in mux master for a mux client session. */
static void
-mux_session_confirm(int id, void *arg)
+mux_session_confirm(int id, int success, void *arg)
{
struct mux_session_confirm_ctx *cctx = arg;
const char *display;
- Channel *c;
+ Channel *c, *cc;
int i;
+ Buffer reply;
if (cctx == NULL)
fatal("%s: cctx == NULL", __func__);
if ((c = channel_by_id(id)) == NULL)
fatal("%s: no channel for id %d", __func__, id);
+ if ((cc = channel_by_id(c->ctl_chan)) == NULL)
+ fatal("%s: channel %d lacks control channel %d", __func__,
+ id, c->ctl_chan);
+
+ if (!success) {
+ debug3("%s: sending failure reply", __func__);
+ /* prepare reply */
+ buffer_init(&reply);
+ buffer_put_int(&reply, MUX_S_FAILURE);
+ buffer_put_int(&reply, cctx->rid);
+ buffer_put_cstring(&reply, "Session open refused by peer");
+ goto done;
+ }
display = getenv("DISPLAY");
if (cctx->want_x_fwd && options.forward_x11 && display != NULL) {
char *proto, *data;
+
/* Get reasonable local authentication information. */
client_x11_get_proto(display, options.xauth_location,
- options.forward_x11_trusted, &proto, &data);
+ options.forward_x11_trusted, options.forward_x11_timeout,
+ &proto, &data);
/* Request forwarding with authentication spoofing. */
- debug("Requesting X11 forwarding with authentication spoofing.");
+ debug("Requesting X11 forwarding with authentication "
+ "spoofing.");
x11_request_forwarding_with_spoofing(id, display, proto, data);
/* XXX wait for reply */
}
@@ -1033,6 +1128,21 @@ mux_session_confirm(int id, void *arg)
client_session2_setup(id, cctx->want_tty, cctx->want_subsys,
cctx->term, &cctx->tio, c->rfd, &cctx->cmd, cctx->env);
+ debug3("%s: sending success reply", __func__);
+ /* prepare reply */
+ buffer_init(&reply);
+ buffer_put_int(&reply, MUX_S_SESSION_OPENED);
+ buffer_put_int(&reply, cctx->rid);
+ buffer_put_int(&reply, c->self);
+
+ done:
+ /* Send reply */
+ buffer_put_string(&cc->output, buffer_ptr(&reply), buffer_len(&reply));
+ buffer_free(&reply);
+
+ if (cc->mux_pause <= 0)
+ fatal("%s: mux_pause %d", __func__, cc->mux_pause);
+ cc->mux_pause = 0; /* start processing messages again */
c->open_confirm_ctx = NULL;
buffer_free(&cctx->cmd);
xfree(cctx->term);
@@ -1365,6 +1475,15 @@ mux_client_request_forward(int fd, u_int ftype, Forward *fwd)
switch (type) {
case MUX_S_OK:
break;
+ case MUX_S_REMOTE_PORT:
+ fwd->allocated_port = buffer_get_int(&m);
+ logit("Allocated port %u for remote forward to %s:%d",
+ fwd->allocated_port,
+ fwd->connect_host ? fwd->connect_host : "",
+ fwd->connect_port);
+ if (muxclient_command == SSHMUX_COMMAND_FORWARD)
+ fprintf(stdout, "%u\n", fwd->allocated_port);
+ break;
case MUX_S_PERMISSION_DENIED:
e = buffer_get_string(&m, NULL);
buffer_free(&m);
@@ -1731,6 +1850,10 @@ muxclient(const char *path)
mux_client_request_terminate(sock);
fprintf(stderr, "Exit request sent.\r\n");
exit(0);
+ case SSHMUX_COMMAND_FORWARD:
+ if (mux_client_request_forwards(sock) != 0)
+ fatal("%s: master forward request failed", __func__);
+ exit(0);
case SSHMUX_COMMAND_OPEN:
if (mux_client_request_forwards(sock) != 0) {
error("%s: master forward request failed", __func__);
diff --git a/crypto/openssh/myproposal.h b/crypto/openssh/myproposal.h
index 98f27fd..7bedfab 100644
--- a/crypto/openssh/myproposal.h
+++ b/crypto/openssh/myproposal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: myproposal.h,v 1.24 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: myproposal.h,v 1.25 2010/04/16 01:47:26 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -40,9 +40,12 @@
"diffie-hellman-group1-sha1"
#endif
-#define KEX_DEFAULT_PK_ALG "ssh-rsa-cert-v00@openssh.com," \
- "ssh-dss-cert-v00@openssh.com," \
- "ssh-rsa,ssh-dss"
+#define KEX_DEFAULT_PK_ALG \
+ "ssh-rsa-cert-v01@openssh.com," \
+ "ssh-dss-cert-v01@openssh.com," \
+ "ssh-rsa-cert-v00@openssh.com," \
+ "ssh-dss-cert-v00@openssh.com," \
+ "ssh-rsa,ssh-dss"
#define KEX_DEFAULT_ENCRYPT \
"aes128-ctr,aes192-ctr,aes256-ctr," \
diff --git a/crypto/openssh/openbsd-compat/openbsd-compat.h b/crypto/openssh/openbsd-compat/openbsd-compat.h
index cad2408..e15d2bd 100644
--- a/crypto/openssh/openbsd-compat/openbsd-compat.h
+++ b/crypto/openssh/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
-/* $Id: openbsd-compat.h,v 1.49 2010/01/16 12:58:37 dtucker Exp $ */
+/* $Id: openbsd-compat.h,v 1.50 2010/08/16 03:15:23 dtucker Exp $ */
/*
* Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -87,6 +87,11 @@ int setenv(register const char *name, register const char *value, int rewrite);
void strmode(int mode, char *p);
#endif
+#ifndef HAVE_STRPTIME
+#include <time.h>
+char *strptime(const char *buf, const char *fmt, struct tm *tm);
+#endif
+
#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
int mkstemps(char *path, int slen);
int mkstemp(char *path);
diff --git a/crypto/openssh/openbsd-compat/openssl-compat.h b/crypto/openssh/openbsd-compat/openssl-compat.h
index fcc7628..b7caa65 100644
--- a/crypto/openssh/openbsd-compat/openssl-compat.h
+++ b/crypto/openssh/openbsd-compat/openssl-compat.h
@@ -1,4 +1,4 @@
-/* $Id: openssl-compat.h,v 1.14 2009/03/07 11:22:35 dtucker Exp $ */
+/* $Id: openssl-compat.h,v 1.15 2010/05/12 07:50:02 djm Exp $ */
/*
* Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au>
@@ -18,6 +18,16 @@
#include "includes.h"
#include <openssl/evp.h>
+#include <openssl/rsa.h>
+#include <openssl/dsa.h>
+
+/* Only in 0.9.8 */
+#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
+# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
+#endif
+#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
+# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
+#endif
/* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */
#if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f)
@@ -97,3 +107,4 @@ int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int);
int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
void ssh_SSLeay_add_all_algorithms(void);
#endif /* SSH_DONT_OVERLOAD_OPENSSL_FUNCS */
+
diff --git a/crypto/openssh/openbsd-compat/port-tun.c b/crypto/openssh/openbsd-compat/port-tun.c
index ddc92d0..0d756f7 100644
--- a/crypto/openssh/openbsd-compat/port-tun.c
+++ b/crypto/openssh/openbsd-compat/port-tun.c
@@ -173,9 +173,11 @@ sys_tun_open(int tun, int mode)
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1)
goto failed;
- ifr.ifr_flags |= IFF_UP;
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1)
- goto failed;
+ if ((ifr.ifr_flags & IFF_UP) == 0) {
+ ifr.ifr_flags |= IFF_UP;
+ if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1)
+ goto failed;
+ }
close(sock);
return (fd);
diff --git a/crypto/openssh/openbsd-compat/port-uw.c b/crypto/openssh/openbsd-compat/port-uw.c
index be9905a..b1fbfa2 100644
--- a/crypto/openssh/openbsd-compat/port-uw.c
+++ b/crypto/openssh/openbsd-compat/port-uw.c
@@ -39,10 +39,10 @@
#include "xmalloc.h"
#include "packet.h"
#include "buffer.h"
+#include "key.h"
#include "auth-options.h"
#include "log.h"
#include "servconf.h"
-#include "key.h"
#include "hostfile.h"
#include "auth.h"
#include "ssh.h"
diff --git a/crypto/openssh/openbsd-compat/strptime.c b/crypto/openssh/openbsd-compat/strptime.c
new file mode 100644
index 0000000..d8d83d9
--- /dev/null
+++ b/crypto/openssh/openbsd-compat/strptime.c
@@ -0,0 +1,401 @@
+/* $OpenBSD: strptime.c,v 1.12 2008/06/26 05:42:05 ray Exp $ */
+/* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code was contributed to The NetBSD Foundation by Klaus Klein.
+ *
+ * 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.
+ */
+
+/* OPENBSD ORIGINAL: lib/libc/time/strptime.c */
+
+#include "includes.h"
+
+#ifndef HAVE_STRPTIME
+
+#define TM_YEAR_BASE 1900 /* from tzfile.h */
+
+#include <ctype.h>
+#include <locale.h>
+#include <string.h>
+#include <time.h>
+
+/* #define _ctloc(x) (_CurrentTimeLocale->x) */
+
+/*
+ * We do not implement alternate representations. However, we always
+ * check whether a given modifier is allowed for a certain conversion.
+ */
+#define _ALT_E 0x01
+#define _ALT_O 0x02
+#define _LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
+
+
+static int _conv_num(const unsigned char **, int *, int, int);
+static char *_strptime(const char *, const char *, struct tm *, int);
+
+
+char *
+strptime(const char *buf, const char *fmt, struct tm *tm)
+{
+ return(_strptime(buf, fmt, tm, 1));
+}
+
+static char *
+_strptime(const char *buf, const char *fmt, struct tm *tm, int initialize)
+{
+ unsigned char c;
+ const unsigned char *bp;
+ size_t len;
+ int alt_format, i;
+ static int century, relyear;
+
+ if (initialize) {
+ century = TM_YEAR_BASE;
+ relyear = -1;
+ }
+
+ bp = (unsigned char *)buf;
+ while ((c = *fmt) != '\0') {
+ /* Clear `alternate' modifier prior to new conversion. */
+ alt_format = 0;
+
+ /* Eat up white-space. */
+ if (isspace(c)) {
+ while (isspace(*bp))
+ bp++;
+
+ fmt++;
+ continue;
+ }
+
+ if ((c = *fmt++) != '%')
+ goto literal;
+
+
+again: switch (c = *fmt++) {
+ case '%': /* "%%" is converted to "%". */
+literal:
+ if (c != *bp++)
+ return (NULL);
+
+ break;
+
+ /*
+ * "Alternative" modifiers. Just set the appropriate flag
+ * and start over again.
+ */
+ case 'E': /* "%E?" alternative conversion modifier. */
+ _LEGAL_ALT(0);
+ alt_format |= _ALT_E;
+ goto again;
+
+ case 'O': /* "%O?" alternative conversion modifier. */
+ _LEGAL_ALT(0);
+ alt_format |= _ALT_O;
+ goto again;
+
+ /*
+ * "Complex" conversion rules, implemented through recursion.
+ */
+#if 0
+ case 'c': /* Date and time, using the locale's format. */
+ _LEGAL_ALT(_ALT_E);
+ if (!(bp = _strptime(bp, _ctloc(d_t_fmt), tm, 0)))
+ return (NULL);
+ break;
+#endif
+ case 'D': /* The date as "%m/%d/%y". */
+ _LEGAL_ALT(0);
+ if (!(bp = _strptime(bp, "%m/%d/%y", tm, 0)))
+ return (NULL);
+ break;
+
+ case 'R': /* The time as "%H:%M". */
+ _LEGAL_ALT(0);
+ if (!(bp = _strptime(bp, "%H:%M", tm, 0)))
+ return (NULL);
+ break;
+
+ case 'r': /* The time as "%I:%M:%S %p". */
+ _LEGAL_ALT(0);
+ if (!(bp = _strptime(bp, "%I:%M:%S %p", tm, 0)))
+ return (NULL);
+ break;
+
+ case 'T': /* The time as "%H:%M:%S". */
+ _LEGAL_ALT(0);
+ if (!(bp = _strptime(bp, "%H:%M:%S", tm, 0)))
+ return (NULL);
+ break;
+#if 0
+ case 'X': /* The time, using the locale's format. */
+ _LEGAL_ALT(_ALT_E);
+ if (!(bp = _strptime(bp, _ctloc(t_fmt), tm, 0)))
+ return (NULL);
+ break;
+
+ case 'x': /* The date, using the locale's format. */
+ _LEGAL_ALT(_ALT_E);
+ if (!(bp = _strptime(bp, _ctloc(d_fmt), tm, 0)))
+ return (NULL);
+ break;
+#endif
+ /*
+ * "Elementary" conversion rules.
+ */
+#if 0
+ case 'A': /* The day of week, using the locale's form. */
+ case 'a':
+ _LEGAL_ALT(0);
+ for (i = 0; i < 7; i++) {
+ /* Full name. */
+ len = strlen(_ctloc(day[i]));
+ if (strncasecmp(_ctloc(day[i]), bp, len) == 0)
+ break;
+
+ /* Abbreviated name. */
+ len = strlen(_ctloc(abday[i]));
+ if (strncasecmp(_ctloc(abday[i]), bp, len) == 0)
+ break;
+ }
+
+ /* Nothing matched. */
+ if (i == 7)
+ return (NULL);
+
+ tm->tm_wday = i;
+ bp += len;
+ break;
+
+ case 'B': /* The month, using the locale's form. */
+ case 'b':
+ case 'h':
+ _LEGAL_ALT(0);
+ for (i = 0; i < 12; i++) {
+ /* Full name. */
+ len = strlen(_ctloc(mon[i]));
+ if (strncasecmp(_ctloc(mon[i]), bp, len) == 0)
+ break;
+
+ /* Abbreviated name. */
+ len = strlen(_ctloc(abmon[i]));
+ if (strncasecmp(_ctloc(abmon[i]), bp, len) == 0)
+ break;
+ }
+
+ /* Nothing matched. */
+ if (i == 12)
+ return (NULL);
+
+ tm->tm_mon = i;
+ bp += len;
+ break;
+#endif
+
+ case 'C': /* The century number. */
+ _LEGAL_ALT(_ALT_E);
+ if (!(_conv_num(&bp, &i, 0, 99)))
+ return (NULL);
+
+ century = i * 100;
+ break;
+
+ case 'd': /* The day of month. */
+ case 'e':
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_mday, 1, 31)))
+ return (NULL);
+ break;
+
+ case 'k': /* The hour (24-hour clock representation). */
+ _LEGAL_ALT(0);
+ /* FALLTHROUGH */
+ case 'H':
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_hour, 0, 23)))
+ return (NULL);
+ break;
+
+ case 'l': /* The hour (12-hour clock representation). */
+ _LEGAL_ALT(0);
+ /* FALLTHROUGH */
+ case 'I':
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_hour, 1, 12)))
+ return (NULL);
+ break;
+
+ case 'j': /* The day of year. */
+ _LEGAL_ALT(0);
+ if (!(_conv_num(&bp, &tm->tm_yday, 1, 366)))
+ return (NULL);
+ tm->tm_yday--;
+ break;
+
+ case 'M': /* The minute. */
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_min, 0, 59)))
+ return (NULL);
+ break;
+
+ case 'm': /* The month. */
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_mon, 1, 12)))
+ return (NULL);
+ tm->tm_mon--;
+ break;
+
+#if 0
+ case 'p': /* The locale's equivalent of AM/PM. */
+ _LEGAL_ALT(0);
+ /* AM? */
+ len = strlen(_ctloc(am_pm[0]));
+ if (strncasecmp(_ctloc(am_pm[0]), bp, len) == 0) {
+ if (tm->tm_hour > 12) /* i.e., 13:00 AM ?! */
+ return (NULL);
+ else if (tm->tm_hour == 12)
+ tm->tm_hour = 0;
+
+ bp += len;
+ break;
+ }
+ /* PM? */
+ len = strlen(_ctloc(am_pm[1]));
+ if (strncasecmp(_ctloc(am_pm[1]), bp, len) == 0) {
+ if (tm->tm_hour > 12) /* i.e., 13:00 PM ?! */
+ return (NULL);
+ else if (tm->tm_hour < 12)
+ tm->tm_hour += 12;
+
+ bp += len;
+ break;
+ }
+
+ /* Nothing matched. */
+ return (NULL);
+#endif
+ case 'S': /* The seconds. */
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_sec, 0, 61)))
+ return (NULL);
+ break;
+
+ case 'U': /* The week of year, beginning on sunday. */
+ case 'W': /* The week of year, beginning on monday. */
+ _LEGAL_ALT(_ALT_O);
+ /*
+ * XXX This is bogus, as we can not assume any valid
+ * information present in the tm structure at this
+ * point to calculate a real value, so just check the
+ * range for now.
+ */
+ if (!(_conv_num(&bp, &i, 0, 53)))
+ return (NULL);
+ break;
+
+ case 'w': /* The day of week, beginning on sunday. */
+ _LEGAL_ALT(_ALT_O);
+ if (!(_conv_num(&bp, &tm->tm_wday, 0, 6)))
+ return (NULL);
+ break;
+
+ case 'Y': /* The year. */
+ _LEGAL_ALT(_ALT_E);
+ if (!(_conv_num(&bp, &i, 0, 9999)))
+ return (NULL);
+
+ relyear = -1;
+ tm->tm_year = i - TM_YEAR_BASE;
+ break;
+
+ case 'y': /* The year within the century (2 digits). */
+ _LEGAL_ALT(_ALT_E | _ALT_O);
+ if (!(_conv_num(&bp, &relyear, 0, 99)))
+ return (NULL);
+ break;
+
+ /*
+ * Miscellaneous conversions.
+ */
+ case 'n': /* Any kind of white-space. */
+ case 't':
+ _LEGAL_ALT(0);
+ while (isspace(*bp))
+ bp++;
+ break;
+
+
+ default: /* Unknown/unsupported conversion. */
+ return (NULL);
+ }
+
+
+ }
+
+ /*
+ * We need to evaluate the two digit year spec (%y)
+ * last as we can get a century spec (%C) at any time.
+ */
+ if (relyear != -1) {
+ if (century == TM_YEAR_BASE) {
+ if (relyear <= 68)
+ tm->tm_year = relyear + 2000 - TM_YEAR_BASE;
+ else
+ tm->tm_year = relyear + 1900 - TM_YEAR_BASE;
+ } else {
+ tm->tm_year = relyear + century - TM_YEAR_BASE;
+ }
+ }
+
+ return ((char *)bp);
+}
+
+
+static int
+_conv_num(const unsigned char **buf, int *dest, int llim, int ulim)
+{
+ int result = 0;
+ int rulim = ulim;
+
+ if (**buf < '0' || **buf > '9')
+ return (0);
+
+ /* we use rulim to break out of the loop when we run out of digits */
+ do {
+ result *= 10;
+ result += *(*buf)++ - '0';
+ rulim /= 10;
+ } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
+
+ if (result < llim || result > ulim)
+ return (0);
+
+ *dest = result;
+ return (1);
+}
+
+#endif /* HAVE_STRPTIME */
+
diff --git a/crypto/openssh/packet.c b/crypto/openssh/packet.c
index 994e35b..48f7fe6 100644
--- a/crypto/openssh/packet.c
+++ b/crypto/openssh/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.166 2009/06/27 09:29:06 andreas Exp $ */
+/* $OpenBSD: packet.c,v 1.168 2010/07/13 23:13:16 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1307,7 +1307,7 @@ packet_read_poll2(u_int32_t *seqnr_p)
macbuf = mac_compute(mac, active_state->p_read.seqnr,
buffer_ptr(&active_state->incoming_packet),
buffer_len(&active_state->incoming_packet));
- if (memcmp(macbuf, buffer_ptr(&active_state->input),
+ if (timingsafe_bcmp(macbuf, buffer_ptr(&active_state->input),
mac->mac_len) != 0) {
logit("Corrupted MAC on input.");
if (need > PACKET_MAX_SIZE)
diff --git a/crypto/openssh/readconf.c b/crypto/openssh/readconf.c
index 6c4bb34..9d6091f 100644
--- a/crypto/openssh/readconf.c
+++ b/crypto/openssh/readconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.c,v 1.183 2010/02/08 10:50:20 markus Exp $ */
+/* $OpenBSD: readconf.c,v 1.187 2010/07/19 09:15:12 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -113,8 +113,8 @@ __RCSID("$FreeBSD$");
typedef enum {
oBadOption,
- oForwardAgent, oForwardX11, oForwardX11Trusted, oGatewayPorts,
- oExitOnForwardFailure,
+ oForwardAgent, oForwardX11, oForwardX11Trusted, oForwardX11Timeout,
+ oGatewayPorts, oExitOnForwardFailure,
oPasswordAuthentication, oRSAAuthentication,
oChallengeResponseAuthentication, oXAuthLocation,
oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
@@ -131,7 +131,8 @@ typedef enum {
oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
oAddressFamily, oGssAuthentication, oGssDelegateCreds,
oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
- oSendEnv, oControlPath, oControlMaster, oHashKnownHosts,
+ oSendEnv, oControlPath, oControlMaster, oControlPersist,
+ oHashKnownHosts,
oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
oVisualHostKey, oUseRoaming, oZeroKnowledgePasswordAuthentication,
oVersionAddendum,
@@ -147,6 +148,7 @@ static struct {
{ "forwardagent", oForwardAgent },
{ "forwardx11", oForwardX11 },
{ "forwardx11trusted", oForwardX11Trusted },
+ { "forwardx11timeout", oForwardX11Timeout },
{ "exitonforwardfailure", oExitOnForwardFailure },
{ "xauthlocation", oXAuthLocation },
{ "gatewayports", oGatewayPorts },
@@ -228,6 +230,7 @@ static struct {
{ "sendenv", oSendEnv },
{ "controlpath", oControlPath },
{ "controlmaster", oControlMaster },
+ { "controlpersist", oControlPersist },
{ "hashknownhosts", oHashKnownHosts },
{ "tunnel", oTunnel },
{ "tunneldevice", oTunnelDevice },
@@ -272,8 +275,9 @@ add_local_forward(Options *options, const Forward *newfwd)
if (newfwd->listen_port < ipport_reserved && original_real_uid != 0)
fatal("Privileged ports can only be forwarded by root.");
#endif
- if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
- fatal("Too many local forwards (max %d).", SSH_MAX_FORWARDS_PER_DIRECTION);
+ options->local_forwards = xrealloc(options->local_forwards,
+ options->num_local_forwards + 1,
+ sizeof(*options->local_forwards));
fwd = &options->local_forwards[options->num_local_forwards++];
fwd->listen_host = newfwd->listen_host;
@@ -291,15 +295,17 @@ void
add_remote_forward(Options *options, const Forward *newfwd)
{
Forward *fwd;
- if (options->num_remote_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)
- fatal("Too many remote forwards (max %d).",
- SSH_MAX_FORWARDS_PER_DIRECTION);
+
+ options->remote_forwards = xrealloc(options->remote_forwards,
+ options->num_remote_forwards + 1,
+ sizeof(*options->remote_forwards));
fwd = &options->remote_forwards[options->num_remote_forwards++];
fwd->listen_host = newfwd->listen_host;
fwd->listen_port = newfwd->listen_port;
fwd->connect_host = newfwd->connect_host;
fwd->connect_port = newfwd->connect_port;
+ fwd->allocated_port = 0;
}
static void
@@ -312,12 +318,20 @@ clear_forwardings(Options *options)
xfree(options->local_forwards[i].listen_host);
xfree(options->local_forwards[i].connect_host);
}
+ if (options->num_local_forwards > 0) {
+ xfree(options->local_forwards);
+ options->local_forwards = NULL;
+ }
options->num_local_forwards = 0;
for (i = 0; i < options->num_remote_forwards; i++) {
if (options->remote_forwards[i].listen_host != NULL)
xfree(options->remote_forwards[i].listen_host);
xfree(options->remote_forwards[i].connect_host);
}
+ if (options->num_remote_forwards > 0) {
+ xfree(options->remote_forwards);
+ options->remote_forwards = NULL;
+ }
options->num_remote_forwards = 0;
options->tun_open = SSH_TUNMODE_NO;
}
@@ -420,6 +434,10 @@ parse_flag:
case oForwardX11Trusted:
intptr = &options->forward_x11_trusted;
goto parse_flag;
+
+ case oForwardX11Timeout:
+ intptr = &options->forward_x11_timeout;
+ goto parse_time;
case oGatewayPorts:
intptr = &options->gateway_ports;
@@ -883,6 +901,30 @@ parse_int:
*intptr = value;
break;
+ case oControlPersist:
+ /* no/false/yes/true, or a time spec */
+ intptr = &options->control_persist;
+ arg = strdelim(&s);
+ if (!arg || *arg == '\0')
+ fatal("%.200s line %d: Missing ControlPersist"
+ " argument.", filename, linenum);
+ value = 0;
+ value2 = 0; /* timeout */
+ if (strcmp(arg, "no") == 0 || strcmp(arg, "false") == 0)
+ value = 0;
+ else if (strcmp(arg, "yes") == 0 || strcmp(arg, "true") == 0)
+ value = 1;
+ else if ((value2 = convtime(arg)) >= 0)
+ value = 1;
+ else
+ fatal("%.200s line %d: Bad ControlPersist argument.",
+ filename, linenum);
+ if (*activep && *intptr == -1) {
+ *intptr = value;
+ options->control_persist_timeout = value2;
+ }
+ break;
+
case oHashKnownHosts:
intptr = &options->hash_known_hosts;
goto parse_flag;
@@ -1031,6 +1073,7 @@ initialize_options(Options * options)
options->forward_agent = -1;
options->forward_x11 = -1;
options->forward_x11_trusted = -1;
+ options->forward_x11_timeout = -1;
options->exit_on_forward_failure = -1;
options->xauth_location = NULL;
options->gateway_ports = -1;
@@ -1071,7 +1114,9 @@ initialize_options(Options * options)
options->user_hostfile = NULL;
options->system_hostfile2 = NULL;
options->user_hostfile2 = NULL;
+ options->local_forwards = NULL;
options->num_local_forwards = 0;
+ options->remote_forwards = NULL;
options->num_remote_forwards = 0;
options->clear_forwardings = -1;
options->log_level = SYSLOG_LEVEL_NOT_SET;
@@ -1088,6 +1133,8 @@ initialize_options(Options * options)
options->num_send_env = 0;
options->control_path = NULL;
options->control_master = -1;
+ options->control_persist = -1;
+ options->control_persist_timeout = 0;
options->hash_known_hosts = -1;
options->tun_open = -1;
options->tun_local = -1;
@@ -1115,6 +1162,8 @@ fill_default_options(Options * options)
options->forward_x11 = 0;
if (options->forward_x11_trusted == -1)
options->forward_x11_trusted = 0;
+ if (options->forward_x11_timeout == -1)
+ options->forward_x11_timeout = 1200;
if (options->exit_on_forward_failure == -1)
options->exit_on_forward_failure = 0;
if (options->xauth_location == NULL)
@@ -1221,6 +1270,10 @@ fill_default_options(Options * options)
options->server_alive_count_max = 3;
if (options->control_master == -1)
options->control_master = 0;
+ if (options->control_persist == -1) {
+ options->control_persist = 0;
+ options->control_persist_timeout = 0;
+ }
if (options->hash_known_hosts == -1)
options->hash_known_hosts = 0;
if (options->tun_open == -1)
diff --git a/crypto/openssh/readconf.h b/crypto/openssh/readconf.h
index 4264751..95d1046 100644
--- a/crypto/openssh/readconf.h
+++ b/crypto/openssh/readconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: readconf.h,v 1.82 2010/02/08 10:50:20 markus Exp $ */
+/* $OpenBSD: readconf.h,v 1.86 2010/07/19 09:15:12 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -23,6 +23,7 @@ typedef struct {
int listen_port; /* Port to forward. */
char *connect_host; /* Host to connect. */
int connect_port; /* Port to connect on connect_host. */
+ int allocated_port; /* Dynamically allocated listen port */
} Forward;
/* Data structure for representing option data. */
@@ -31,6 +32,7 @@ typedef struct {
typedef struct {
int forward_agent; /* Forward authentication agent. */
int forward_x11; /* Forward X11 display. */
+ int forward_x11_timeout; /* Expiration for Cookies */
int forward_x11_trusted; /* Trust Forward X11 display. */
int exit_on_forward_failure; /* Exit if bind(2) fails for -L/-R */
char *xauth_location; /* Location for xauth program */
@@ -93,11 +95,11 @@ typedef struct {
/* Local TCP/IP forward requests. */
int num_local_forwards;
- Forward local_forwards[SSH_MAX_FORWARDS_PER_DIRECTION];
+ Forward *local_forwards;
/* Remote TCP/IP forward requests. */
int num_remote_forwards;
- Forward remote_forwards[SSH_MAX_FORWARDS_PER_DIRECTION];
+ Forward *remote_forwards;
int clear_forwardings;
int enable_ssh_keysign;
@@ -112,6 +114,8 @@ typedef struct {
char *control_path;
int control_master;
+ int control_persist; /* ControlPersist flag */
+ int control_persist_timeout; /* ControlPersist timeout (seconds) */
int hash_known_hosts;
diff --git a/crypto/openssh/scp.c b/crypto/openssh/scp.c
index 09efb82..e07de42 100644
--- a/crypto/openssh/scp.c
+++ b/crypto/openssh/scp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scp.c,v 1.165 2009/12/20 07:28:36 guenther Exp $ */
+/* $OpenBSD: scp.c,v 1.166 2010/07/01 13:06:59 millert Exp $ */
/*
* scp - secure remote copy. This is basically patched BSD rcp which
* uses ssh to do the data transfer (instead of using rcmd).
@@ -156,6 +156,20 @@ killchild(int signo)
exit(1);
}
+static void
+suspchild(int signo)
+{
+ int status;
+
+ if (do_cmd_pid > 1) {
+ kill(do_cmd_pid, signo);
+ while (waitpid(do_cmd_pid, &status, WUNTRACED) == -1 &&
+ errno == EINTR)
+ ;
+ kill(getpid(), SIGSTOP);
+ }
+}
+
static int
do_local_cmd(arglist *a)
{
@@ -232,6 +246,10 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
close(reserved[0]);
close(reserved[1]);
+ signal(SIGTSTP, suspchild);
+ signal(SIGTTIN, suspchild);
+ signal(SIGTTOU, suspchild);
+
/* Fork a child to execute the command on the remote host using ssh. */
do_cmd_pid = fork();
if (do_cmd_pid == 0) {
diff --git a/crypto/openssh/servconf.c b/crypto/openssh/servconf.c
index 626f38c..506cf2e 100644
--- a/crypto/openssh/servconf.c
+++ b/crypto/openssh/servconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: servconf.c,v 1.207 2010/03/25 23:38:28 djm Exp $ */
+/* $OpenBSD: servconf.c,v 1.209 2010/06/22 04:22:59 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -133,6 +133,7 @@ initialize_server_options(ServerOptions *options)
options->zero_knowledge_password_authentication = -1;
options->revoked_keys_file = NULL;
options->trusted_user_ca_keys = NULL;
+ options->authorized_principals_file = NULL;
}
void
@@ -312,7 +313,7 @@ typedef enum {
sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
sUsePrivilegeSeparation, sAllowAgentForwarding,
sZeroKnowledgePasswordAuthentication, sHostCertificate,
- sRevokedKeys, sTrustedUserCAKeys,
+ sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
sVersionAddendum,
sDeprecated, sUnsupported
} ServerOpCodes;
@@ -348,7 +349,7 @@ static struct {
{ "rhostsauthentication", sDeprecated, SSHCFG_GLOBAL },
{ "rhostsrsaauthentication", sRhostsRSAAuthentication, SSHCFG_ALL },
{ "hostbasedauthentication", sHostbasedAuthentication, SSHCFG_ALL },
- { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_GLOBAL },
+ { "hostbasedusesnamefrompacketonly", sHostbasedUsesNameFromPacketOnly, SSHCFG_ALL },
{ "rsaauthentication", sRSAAuthentication, SSHCFG_ALL },
{ "pubkeyauthentication", sPubkeyAuthentication, SSHCFG_ALL },
{ "dsaauthentication", sPubkeyAuthentication, SSHCFG_GLOBAL }, /* alias */
@@ -423,11 +424,11 @@ static struct {
{ "reversemappingcheck", sDeprecated, SSHCFG_GLOBAL },
{ "clientaliveinterval", sClientAliveInterval, SSHCFG_GLOBAL },
{ "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
- { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_GLOBAL },
- { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_GLOBAL },
+ { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
+ { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_ALL },
{ "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
{ "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
- { "permittunnel", sPermitTunnel, SSHCFG_GLOBAL },
+ { "permittunnel", sPermitTunnel, SSHCFG_ALL },
{ "match", sMatch, SSHCFG_ALL },
{ "permitopen", sPermitOpen, SSHCFG_ALL },
{ "forcecommand", sForceCommand, SSHCFG_ALL },
@@ -435,6 +436,7 @@ static struct {
{ "hostcertificate", sHostCertificate, SSHCFG_GLOBAL },
{ "revokedkeys", sRevokedKeys, SSHCFG_ALL },
{ "trustedusercakeys", sTrustedUserCAKeys, SSHCFG_ALL },
+ { "authorizedprincipalsfile", sAuthorizedPrincipalsFile, SSHCFG_ALL },
{ "versionaddendum", sVersionAddendum, SSHCFG_GLOBAL },
{ NULL, sBadOption, 0 }
};
@@ -1222,10 +1224,14 @@ process_server_config_line(ServerOptions *options, char *line,
* AuthorizedKeysFile /etc/ssh_keys/%u
*/
case sAuthorizedKeysFile:
+ charptr = &options->authorized_keys_file;
+ goto parse_tilde_filename;
case sAuthorizedKeysFile2:
- charptr = (opcode == sAuthorizedKeysFile) ?
- &options->authorized_keys_file :
- &options->authorized_keys_file2;
+ charptr = &options->authorized_keys_file2;
+ goto parse_tilde_filename;
+ case sAuthorizedPrincipalsFile:
+ charptr = &options->authorized_principals_file;
+ parse_tilde_filename:
arg = strdelim(&cp);
if (!arg || *arg == '\0')
fatal("%s line %d: missing file name.",
@@ -1451,6 +1457,7 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
M_CP_INTOPT(pubkey_authentication);
M_CP_INTOPT(kerberos_authentication);
M_CP_INTOPT(hostbased_authentication);
+ M_CP_INTOPT(hostbased_uses_name_from_packet_only);
M_CP_INTOPT(kbd_interactive_authentication);
M_CP_INTOPT(zero_knowledge_password_authentication);
M_CP_INTOPT(permit_root_login);
@@ -1458,6 +1465,7 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
M_CP_INTOPT(allow_tcp_forwarding);
M_CP_INTOPT(allow_agent_forwarding);
+ M_CP_INTOPT(permit_tun);
M_CP_INTOPT(gateway_ports);
M_CP_INTOPT(x11_display_offset);
M_CP_INTOPT(x11_forwarding);
@@ -1472,6 +1480,9 @@ copy_set_server_options(ServerOptions *dst, ServerOptions *src, int preauth)
M_CP_STROPT(chroot_directory);
M_CP_STROPT(trusted_user_ca_keys);
M_CP_STROPT(revoked_keys_file);
+ M_CP_STROPT(authorized_keys_file);
+ M_CP_STROPT(authorized_keys_file2);
+ M_CP_STROPT(authorized_principals_file);
}
#undef M_CP_INTOPT
@@ -1693,6 +1704,8 @@ dump_config(ServerOptions *o)
dump_cfg_string(sChrootDirectory, o->chroot_directory);
dump_cfg_string(sTrustedUserCAKeys, o->trusted_user_ca_keys);
dump_cfg_string(sRevokedKeys, o->revoked_keys_file);
+ dump_cfg_string(sAuthorizedPrincipalsFile,
+ o->authorized_principals_file);
/* string arguments requiring a lookup */
dump_cfg_string(sLogLevel, log_level_name(o->log_level));
diff --git a/crypto/openssh/servconf.h b/crypto/openssh/servconf.h
index 860009f..45d2a2a 100644
--- a/crypto/openssh/servconf.h
+++ b/crypto/openssh/servconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: servconf.h,v 1.92 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: servconf.h,v 1.93 2010/05/07 11:30:30 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -156,6 +156,7 @@ typedef struct {
char *chroot_directory;
char *revoked_keys_file;
char *trusted_user_ca_keys;
+ char *authorized_principals_file;
} ServerOptions;
void initialize_server_options(ServerOptions *);
diff --git a/crypto/openssh/session.c b/crypto/openssh/session.c
index 9fa7213..bc4d7a9 100644
--- a/crypto/openssh/session.c
+++ b/crypto/openssh/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.252 2010/03/07 11:57:13 dtucker Exp $ */
+/* $OpenBSD: session.c,v 1.256 2010/06/25 07:20:04 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -48,6 +48,7 @@ __RCSID("$FreeBSD$");
#include <arpa/inet.h>
#include <errno.h>
+#include <fcntl.h>
#include <grp.h>
#ifdef HAVE_PATHS_H
#include <paths.h>
@@ -105,7 +106,7 @@ __RCSID("$FreeBSD$");
/* func */
Session *session_new(void);
-void session_set_fds(Session *, int, int, int, int);
+void session_set_fds(Session *, int, int, int, int, int);
void session_pty_cleanup(Session *);
void session_proctitle(Session *);
int session_setup_x11fwd(Session *);
@@ -448,6 +449,9 @@ do_exec_no_pty(Session *s, const char *command)
#ifdef USE_PIPES
int pin[2], pout[2], perr[2];
+ if (s == NULL)
+ fatal("do_exec_no_pty: no session");
+
/* Allocate pipes for communicating with the program. */
if (pipe(pin) < 0) {
error("%s: pipe in: %.100s", __func__, strerror(errno));
@@ -460,7 +464,8 @@ do_exec_no_pty(Session *s, const char *command)
return -1;
}
if (pipe(perr) < 0) {
- error("%s: pipe err: %.100s", __func__, strerror(errno));
+ error("%s: pipe err: %.100s", __func__,
+ strerror(errno));
close(pin[0]);
close(pin[1]);
close(pout[0]);
@@ -470,22 +475,23 @@ do_exec_no_pty(Session *s, const char *command)
#else
int inout[2], err[2];
+ if (s == NULL)
+ fatal("do_exec_no_pty: no session");
+
/* Uses socket pairs to communicate with the program. */
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0) {
error("%s: socketpair #1: %.100s", __func__, strerror(errno));
return -1;
}
if (socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) {
- error("%s: socketpair #2: %.100s", __func__, strerror(errno));
+ error("%s: socketpair #2: %.100s", __func__,
+ strerror(errno));
close(inout[0]);
close(inout[1]);
return -1;
}
#endif
- if (s == NULL)
- fatal("do_exec_no_pty: no session");
-
session_proctitle(s);
/* Fork the child. */
@@ -596,11 +602,8 @@ do_exec_no_pty(Session *s, const char *command)
close(perr[1]);
if (compat20) {
- if (s->is_subsystem) {
- close(perr[0]);
- perr[0] = -1;
- }
- session_set_fds(s, pin[1], pout[0], perr[0], 0);
+ session_set_fds(s, pin[1], pout[0], perr[0],
+ s->is_subsystem, 0);
} else {
/* Enter the interactive session. */
server_loop(pid, pin[1], pout[0], perr[0]);
@@ -616,10 +619,8 @@ do_exec_no_pty(Session *s, const char *command)
* handle the case that fdin and fdout are the same.
*/
if (compat20) {
- session_set_fds(s, inout[1], inout[1],
- s->is_subsystem ? -1 : err[1], 0);
- if (s->is_subsystem)
- close(err[1]);
+ session_set_fds(s, inout[1], inout[1], err[1],
+ s->is_subsystem, 0);
} else {
server_loop(pid, inout[1], inout[1], err[1]);
/* server_loop has closed inout[1] and err[1]. */
@@ -741,7 +742,7 @@ do_exec_pty(Session *s, const char *command)
s->ptymaster = ptymaster;
packet_set_interactive(1);
if (compat20) {
- session_set_fds(s, ptyfd, fdout, -1, 1);
+ session_set_fds(s, ptyfd, fdout, -1, 1, 1);
} else {
server_loop(pid, ptyfd, fdout, -1);
/* server_loop _has_ closed ptyfd and fdout. */
@@ -1804,7 +1805,8 @@ do_child(Session *s, const char *command)
#ifdef HAVE_LOGIN_CAP
r = login_getcapbool(lc, "requirehome", 0);
#endif
- if (r || options.chroot_directory == NULL)
+ if (r || options.chroot_directory == NULL ||
+ strcasecmp(options.chroot_directory, "none") == 0)
fprintf(stderr, "Could not chdir to home "
"directory %s: %s\n", pw->pw_dir,
strerror(errno));
@@ -2149,7 +2151,8 @@ session_subsystem_req(Session *s)
u_int i;
packet_check_eom();
- logit("subsystem request for %.100s", subsys);
+ logit("subsystem request for %.100s by user %s", subsys,
+ s->pw->pw_name);
for (i = 0; i < options.num_subsystems; i++) {
if (strcmp(subsys, options.subsystem_name[i]) == 0) {
@@ -2331,7 +2334,8 @@ session_input_channel_req(Channel *c, const char *rtype)
}
void
-session_set_fds(Session *s, int fdin, int fdout, int fderr, int is_tty)
+session_set_fds(Session *s, int fdin, int fdout, int fderr, int ignore_fderr,
+ int is_tty)
{
if (!compat20)
fatal("session_set_fds: called for proto != 2.0");
@@ -2343,7 +2347,7 @@ session_set_fds(Session *s, int fdin, int fdout, int fderr, int is_tty)
fatal("no channel for session %d", s->self);
channel_set_fds(s->chanid,
fdout, fdin, fderr,
- fderr == -1 ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
+ ignore_fderr ? CHAN_EXTENDED_IGNORE : CHAN_EXTENDED_READ,
1, is_tty, CHAN_SES_WINDOW_DEFAULT);
}
diff --git a/crypto/openssh/sftp-client.c b/crypto/openssh/sftp-client.c
index 6124c0f..9dab477 100644
--- a/crypto/openssh/sftp-client.c
+++ b/crypto/openssh/sftp-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.90 2009/10/11 10:41:26 dtucker Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.92 2010/07/19 03:16:33 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -713,7 +713,8 @@ do_realpath(struct sftp_conn *conn, char *path)
u_int status = buffer_get_int(&msg);
error("Couldn't canonicalise: %s", fx2txt(status));
- return(NULL);
+ buffer_free(&msg);
+ return NULL;
} else if (type != SSH2_FXP_NAME)
fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
SSH2_FXP_NAME, type);
@@ -1522,7 +1523,7 @@ upload_dir_internal(struct sftp_conn *conn, char *src, char *dst,
continue;
if (upload_dir_internal(conn, new_src, new_dst,
- pflag, depth + 1, printflag) == -1)
+ pflag, printflag, depth + 1) == -1)
ret = -1;
} else if (S_ISREG(sb.st_mode)) {
if (do_upload(conn, new_src, new_dst, pflag) == -1) {
diff --git a/crypto/openssh/sftp.c b/crypto/openssh/sftp.c
index d65d4ec..229f129 100644
--- a/crypto/openssh/sftp.c
+++ b/crypto/openssh/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.123 2010/01/27 19:21:39 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.125 2010/06/18 00:58:39 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -181,6 +181,8 @@ static const struct CMD cmds[] = {
{ "ls", I_LS, REMOTE },
{ "lumask", I_LUMASK, NOARGS },
{ "mkdir", I_MKDIR, REMOTE },
+ { "mget", I_GET, REMOTE },
+ { "mput", I_PUT, LOCAL },
{ "progress", I_PROGRESS, NOARGS },
{ "put", I_PUT, LOCAL },
{ "pwd", I_PWD, REMOTE },
@@ -1366,7 +1368,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
break;
case I_LS:
if (!path1) {
- do_globbed_ls(conn, *pwd, *pwd, lflag);
+ do_ls_dir(conn, *pwd, *pwd, lflag);
break;
}
diff --git a/crypto/openssh/ssh-add.c b/crypto/openssh/ssh-add.c
index ad9f7a8..fb641ec 100644
--- a/crypto/openssh/ssh-add.c
+++ b/crypto/openssh/ssh-add.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-add.c,v 1.94 2010/03/01 11:07:06 otto Exp $ */
+/* $OpenBSD: ssh-add.c,v 1.96 2010/05/14 00:47:22 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -194,7 +194,7 @@ add_file(AuthenticationConnection *ac, const char *filename)
"Lifetime set to %d seconds\n", lifetime);
if (confirm != 0)
fprintf(stderr,
- "The user has to confirm each use of the key\n");
+ "The user must confirm each use of the key\n");
} else {
fprintf(stderr, "Could not add identity: %s\n", filename);
}
@@ -202,29 +202,37 @@ add_file(AuthenticationConnection *ac, const char *filename)
/* Now try to add the certificate flavour too */
xasprintf(&certpath, "%s-cert.pub", filename);
- if ((cert = key_load_public(certpath, NULL)) != NULL) {
- /* Graft with private bits */
- if (key_to_certified(private) != 0)
- fatal("%s: key_to_certified failed", __func__);
- key_cert_copy(cert, private);
+ if ((cert = key_load_public(certpath, NULL)) == NULL)
+ goto out;
+
+ if (!key_equal_public(cert, private)) {
+ error("Certificate %s does not match private key %s",
+ certpath, filename);
key_free(cert);
+ goto out;
+ }
- if (ssh_add_identity_constrained(ac, private, comment,
- lifetime, confirm)) {
- fprintf(stderr, "Certificate added: %s (%s)\n",
- certpath, private->cert->key_id);
- if (lifetime != 0)
- fprintf(stderr, "Lifetime set to %d seconds\n",
- lifetime);
- if (confirm != 0)
- fprintf(stderr, "The user has to confirm each "
- "use of the key\n");
- } else {
- error("Certificate %s (%s) add failed", certpath,
- private->cert->key_id);
- }
+ /* Graft with private bits */
+ if (key_to_certified(private, key_cert_is_legacy(cert)) != 0) {
+ error("%s: key_to_certified failed", __func__);
+ key_free(cert);
+ goto out;
}
+ key_cert_copy(cert, private);
+ key_free(cert);
+ if (!ssh_add_identity_constrained(ac, private, comment,
+ lifetime, confirm)) {
+ error("Certificate %s (%s) add failed", certpath,
+ private->cert->key_id);
+ }
+ fprintf(stderr, "Certificate added: %s (%s)\n", certpath,
+ private->cert->key_id);
+ if (lifetime != 0)
+ fprintf(stderr, "Lifetime set to %d seconds\n", lifetime);
+ if (confirm != 0)
+ fprintf(stderr, "The user must confirm each use of the key\n");
+ out:
xfree(certpath);
xfree(comment);
key_free(private);
diff --git a/crypto/openssh/ssh-agent.c b/crypto/openssh/ssh-agent.c
index 320591b..edd65a2 100644
--- a/crypto/openssh/ssh-agent.c
+++ b/crypto/openssh/ssh-agent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-agent.c,v 1.165 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: ssh-agent.c,v 1.166 2010/04/16 01:47:26 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -501,6 +501,7 @@ process_add_identity(SocketEntry *e, int version)
buffer_get_bignum2(&e->request, k->dsa->pub_key);
buffer_get_bignum2(&e->request, k->dsa->priv_key);
break;
+ case KEY_DSA_CERT_V00:
case KEY_DSA_CERT:
cert = buffer_get_string(&e->request, &len);
if ((k = key_from_blob(cert, len)) == NULL)
@@ -521,6 +522,7 @@ process_add_identity(SocketEntry *e, int version)
/* Generate additional parameters */
rsa_generate_additional_parameters(k->rsa);
break;
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
cert = buffer_get_string(&e->request, &len);
if ((k = key_from_blob(cert, len)) == NULL)
@@ -541,6 +543,7 @@ process_add_identity(SocketEntry *e, int version)
/* enable blinding */
switch (k->type) {
case KEY_RSA:
+ case KEY_RSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_RSA1:
if (RSA_blinding_on(k->rsa, NULL) != 1) {
diff --git a/crypto/openssh/ssh-dss.c b/crypto/openssh/ssh-dss.c
index 449f493..175e4d0 100644
--- a/crypto/openssh/ssh-dss.c
+++ b/crypto/openssh/ssh-dss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-dss.c,v 1.25 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: ssh-dss.c,v 1.26 2010/04/16 01:47:26 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -53,9 +53,8 @@ ssh_dss_sign(const Key *key, u_char **sigp, u_int *lenp,
u_int rlen, slen, len, dlen;
Buffer b;
- if (key == NULL ||
- (key->type != KEY_DSA && key->type != KEY_DSA_CERT) ||
- key->dsa == NULL) {
+ if (key == NULL || key->dsa == NULL || (key->type != KEY_DSA &&
+ key->type != KEY_DSA_CERT && key->type != KEY_DSA_CERT_V00)) {
error("ssh_dss_sign: no DSA key");
return -1;
}
@@ -118,9 +117,8 @@ ssh_dss_verify(const Key *key, const u_char *signature, u_int signaturelen,
int rlen, ret;
Buffer b;
- if (key == NULL ||
- (key->type != KEY_DSA && key->type != KEY_DSA_CERT) ||
- key->dsa == NULL) {
+ if (key == NULL || key->dsa == NULL || (key->type != KEY_DSA &&
+ key->type != KEY_DSA_CERT && key->type != KEY_DSA_CERT_V00)) {
error("ssh_dss_verify: no DSA key");
return -1;
}
diff --git a/crypto/openssh/ssh-keygen.1 b/crypto/openssh/ssh-keygen.1
index 855a1d5..5a04fc0 100644
--- a/crypto/openssh/ssh-keygen.1
+++ b/crypto/openssh/ssh-keygen.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ssh-keygen.1,v 1.92 2010/03/13 23:38:13 jmc Exp $
+.\" $OpenBSD: ssh-keygen.1,v 1.98 2010/08/04 06:07:11 djm Exp $
.\" $FreeBSD$
.\"
.\" -*- nroff -*-
@@ -38,15 +38,15 @@
.\" (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 March 13, 2010
+.Dd August 4, 2010
.Dt SSH-KEYGEN 1
.Os
.Sh NAME
.Nm ssh-keygen
.Nd authentication key generation, management and conversion
.Sh SYNOPSIS
-.Nm ssh-keygen
.Bk -words
+.Nm ssh-keygen
.Op Fl q
.Op Fl b Ar bits
.Fl t Ar type
@@ -60,9 +60,11 @@
.Op Fl f Ar keyfile
.Nm ssh-keygen
.Fl i
+.Op Fl m Ar key_format
.Op Fl f Ar input_keyfile
.Nm ssh-keygen
.Fl e
+.Op Fl m Ar key_format
.Op Fl f Ar input_keyfile
.Nm ssh-keygen
.Fl y
@@ -111,8 +113,9 @@
.Fl I Ar certificate_identity
.Op Fl h
.Op Fl n Ar principals
-.Op Fl O Ar constraint
+.Op Fl O Ar option
.Op Fl V Ar validity_interval
+.Op Fl z Ar serial_number
.Ar
.Nm ssh-keygen
.Fl L
@@ -213,13 +216,20 @@ the passphrase if the key has one, and for the new comment.
.It Fl D Ar pkcs11
Download the RSA public keys provided by the PKCS#11 shared library
.Ar pkcs11 .
+When used in combination with
+.Fl s ,
+this option indicates that a CA key resides in a PKCS#11 token (see the
+.Sx CERTIFICATES
+section for details).
.It Fl e
This option will read a private or public OpenSSH key file and
-print the key in
-RFC 4716 SSH Public Key File Format
-to stdout.
-This option allows exporting keys for use by several commercial
-SSH implementations.
+print to stdout the key in one of the formats specified by the
+.Fl m
+option.
+The default export format is
+.Dq RFC4716 .
+This option allows exporting OpenSSH keys for use by other programs, including
+several commercial SSH implementations.
.It Fl F Ar hostname
Search for the specified
.Ar hostname
@@ -270,13 +280,14 @@ Please see the
section for details.
.It Fl i
This option will read an unencrypted private (or public) key file
-in SSH2-compatible format and print an OpenSSH compatible private
+in the format specified by the
+.Fl m
+option and print an OpenSSH compatible private
(or public) key to stdout.
-.Nm
-also reads the
-RFC 4716 SSH Public Key File Format.
-This option allows importing keys from several commercial
-SSH implementations.
+This option allows importing keys from other software, including several
+commercial SSH implementations.
+The default import format is
+.Dq RFC4716 .
.It Fl L
Prints the contents of a certificate.
.It Fl l
@@ -291,6 +302,22 @@ an ASCII art representation of the key is supplied with the fingerprint.
.It Fl M Ar memory
Specify the amount of memory to use (in megabytes) when generating
candidate moduli for DH-GEX.
+.It Fl m Ar key_format
+Specify a key format for the
+.Fl i
+(import) or
+.Fl e
+(export) conversion options.
+The supported key formats are:
+.Dq RFC4716
+(RFC 4716/SSH2 public or private key),
+.Dq PKCS8
+(PEM PKCS8 public key)
+or
+.Dq PEM
+(PEM public key).
+The default conversion format is
+.Dq RFC4716 .
.It Fl N Ar new_passphrase
Provides the new passphrase.
.It Fl n Ar principals
@@ -300,13 +327,13 @@ Multiple principals may be specified, separated by commas.
Please see the
.Sx CERTIFICATES
section for details.
-.It Fl O Ar constraint
-Specify a certificate constraint when signing a key.
+.It Fl O Ar option
+Specify a certificate option when signing a key.
This option may be specified multiple times.
Please see the
.Sx CERTIFICATES
section for details.
-The constraints that are valid for user certificates are:
+The options that are valid for user certificates are:
.Bl -tag -width Ds
.It Ic clear
Clear all enabled permissions.
@@ -356,7 +383,7 @@ is a comma-separated list of one or more address/netmask pairs in CIDR
format.
.El
.Pp
-At present, no constraints are valid for host keys.
+At present, no options are valid for host keys.
.It Fl P Ar passphrase
Provides the (old) passphrase.
.It Fl p
@@ -442,6 +469,10 @@ Specify desired generator when testing candidate moduli for DH-GEX.
.It Fl y
This option will read a private
OpenSSH format file and print an OpenSSH public key to stdout.
+.It Fl z Ar serial_number
+Specifies a serial number to be embedded in the certificate to distinguish
+this certificate from others from the same CA.
+The default serial number is zero.
.El
.Sh MODULI GENERATION
.Nm
@@ -502,7 +533,7 @@ that both ends of a connection share common moduli.
supports signing of keys to produce certificates that may be used for
user or host authentication.
Certificates consist of a public key, some identity information, zero or
-more principal (user or host) names and an optional set of constraints that
+more principal (user or host) names and a set of options that
are signed by a Certification Authority (CA) key.
Clients or servers may then trust only the CA key and verify its signature
on a certificate rather than trusting many user/host keys.
@@ -528,7 +559,17 @@ option:
.Pp
The host certificate will be output to
.Pa /path/to/host_key-cert.pub .
-In both cases,
+.Pp
+It is possible to sign using a CA key stored in a PKCS#11 token by
+providing the token library using
+.Fl D
+and identifying the CA key by providing its public half as an argument
+to
+.Fl s :
+.Pp
+.Dl $ ssh-keygen -s ca_key.pub -D libpkcs11.so -I key_id host_key.pub
+.Pp
+In all cases,
.Ar key_id
is a "key identifier" that is logged by the server when the certificate
is used for authentication.
@@ -542,11 +583,11 @@ To generate a certificate for a specified set of principals:
.Dl "$ ssh-keygen -s ca_key -I key_id -h -n host.domain user_key.pub"
.Pp
Additional limitations on the validity and use of user certificates may
-be specified through certificate constraints.
-A constrained certificate may disable features of the SSH session, may be
+be specified through certificate options.
+A certificate option may disable features of the SSH session, may be
valid only when presented from particular source addresses or may
force the use of a specific command.
-For a list of valid certificate constraints, see the documentation for the
+For a list of valid certificate options, see the documentation for the
.Fl O
option above.
.Pp
diff --git a/crypto/openssh/ssh-keygen.c b/crypto/openssh/ssh-keygen.c
index 37e516f..d90b1df 100644
--- a/crypto/openssh/ssh-keygen.c
+++ b/crypto/openssh/ssh-keygen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.185 2010/03/15 19:40:02 stevesk Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.197 2010/08/04 06:07:11 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -105,6 +105,9 @@ char *identity_comment = NULL;
/* Path to CA key when certifying keys. */
char *ca_key_path = NULL;
+/* Certificate serial number */
+long long cert_serial = 0;
+
/* Key type when certifying */
u_int cert_key_type = SSH2_CERT_TYPE_USER;
@@ -118,27 +121,34 @@ char *cert_principals = NULL;
u_int64_t cert_valid_from = 0;
u_int64_t cert_valid_to = ~0ULL;
-/* Certificate constraints */
-#define CONSTRAINT_X_FWD (1)
-#define CONSTRAINT_AGENT_FWD (1<<1)
-#define CONSTRAINT_PORT_FWD (1<<2)
-#define CONSTRAINT_PTY (1<<3)
-#define CONSTRAINT_USER_RC (1<<4)
-#define CONSTRAINT_DEFAULT (CONSTRAINT_X_FWD|CONSTRAINT_AGENT_FWD| \
- CONSTRAINT_PORT_FWD|CONSTRAINT_PTY| \
- CONSTRAINT_USER_RC)
-u_int32_t constraint_flags = CONSTRAINT_DEFAULT;
-char *constraint_command = NULL;
-char *constraint_src_addr = NULL;
-
-/* Dump public key file in format used by real and the original SSH 2 */
-int convert_to_ssh2 = 0;
-int convert_from_ssh2 = 0;
+/* Certificate options */
+#define CERTOPT_X_FWD (1)
+#define CERTOPT_AGENT_FWD (1<<1)
+#define CERTOPT_PORT_FWD (1<<2)
+#define CERTOPT_PTY (1<<3)
+#define CERTOPT_USER_RC (1<<4)
+#define CERTOPT_DEFAULT (CERTOPT_X_FWD|CERTOPT_AGENT_FWD| \
+ CERTOPT_PORT_FWD|CERTOPT_PTY|CERTOPT_USER_RC)
+u_int32_t certflags_flags = CERTOPT_DEFAULT;
+char *certflags_command = NULL;
+char *certflags_src_addr = NULL;
+
+/* Conversion to/from various formats */
+int convert_to = 0;
+int convert_from = 0;
+enum {
+ FMT_RFC4716,
+ FMT_PKCS8,
+ FMT_PEM
+} convert_format = FMT_RFC4716;
int print_public = 0;
int print_generic = 0;
char *key_type_name = NULL;
+/* Load key from this PKCS#11 provider */
+char *pkcs11provider = NULL;
+
/* argv0 */
extern char *__progname;
@@ -161,9 +171,13 @@ ask_filename(struct passwd *pw, const char *prompt)
case KEY_RSA1:
name = _PATH_SSH_CLIENT_IDENTITY;
break;
+ case KEY_DSA_CERT:
+ case KEY_DSA_CERT_V00:
case KEY_DSA:
name = _PATH_SSH_CLIENT_ID_DSA;
break;
+ case KEY_RSA_CERT:
+ case KEY_RSA_CERT_V00:
case KEY_RSA:
name = _PATH_SSH_CLIENT_ID_RSA;
break;
@@ -209,30 +223,12 @@ load_identity(char *filename)
#define SSH_COM_PRIVATE_KEY_MAGIC 0x3f6ff9eb
static void
-do_convert_to_ssh2(struct passwd *pw)
+do_convert_to_ssh2(struct passwd *pw, Key *k)
{
- Key *k;
u_int len;
u_char *blob;
char comment[61];
- struct stat st;
- if (!have_identity)
- ask_filename(pw, "Enter file in which the key is");
- if (stat(identity_file, &st) < 0) {
- perror(identity_file);
- exit(1);
- }
- if ((k = key_load_public(identity_file, NULL)) == NULL) {
- if ((k = load_identity(identity_file)) == NULL) {
- fprintf(stderr, "load failed\n");
- exit(1);
- }
- }
- if (k->type == KEY_RSA1) {
- fprintf(stderr, "version 1 keys are not supported\n");
- exit(1);
- }
if (key_to_blob(k, &blob, &len) <= 0) {
fprintf(stderr, "key_to_blob failed\n");
exit(1);
@@ -253,6 +249,81 @@ do_convert_to_ssh2(struct passwd *pw)
}
static void
+do_convert_to_pkcs8(Key *k)
+{
+ switch (key_type_plain(k->type)) {
+ case KEY_RSA:
+ if (!PEM_write_RSA_PUBKEY(stdout, k->rsa))
+ fatal("PEM_write_RSA_PUBKEY failed");
+ break;
+ case KEY_DSA:
+ if (!PEM_write_DSA_PUBKEY(stdout, k->dsa))
+ fatal("PEM_write_DSA_PUBKEY failed");
+ break;
+ default:
+ fatal("%s: unsupported key type %s", __func__, key_type(k));
+ }
+ exit(0);
+}
+
+static void
+do_convert_to_pem(Key *k)
+{
+ switch (key_type_plain(k->type)) {
+ case KEY_RSA:
+ if (!PEM_write_RSAPublicKey(stdout, k->rsa))
+ fatal("PEM_write_RSAPublicKey failed");
+ break;
+#if notyet /* OpenSSH 0.9.8 lacks this function */
+ case KEY_DSA:
+ if (!PEM_write_DSAPublicKey(stdout, k->dsa))
+ fatal("PEM_write_DSAPublicKey failed");
+ break;
+#endif
+ default:
+ fatal("%s: unsupported key type %s", __func__, key_type(k));
+ }
+ exit(0);
+}
+
+static void
+do_convert_to(struct passwd *pw)
+{
+ Key *k;
+ struct stat st;
+
+ if (!have_identity)
+ ask_filename(pw, "Enter file in which the key is");
+ if (stat(identity_file, &st) < 0)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
+ if ((k = key_load_public(identity_file, NULL)) == NULL) {
+ if ((k = load_identity(identity_file)) == NULL) {
+ fprintf(stderr, "load failed\n");
+ exit(1);
+ }
+ }
+ if (k->type == KEY_RSA1) {
+ fprintf(stderr, "version 1 keys are not supported\n");
+ exit(1);
+ }
+
+ switch (convert_format) {
+ case FMT_RFC4716:
+ do_convert_to_ssh2(pw, k);
+ break;
+ case FMT_PKCS8:
+ do_convert_to_pkcs8(k);
+ break;
+ case FMT_PEM:
+ do_convert_to_pem(k);
+ break;
+ default:
+ fatal("%s: unknown key format %d", __func__, convert_format);
+ }
+ exit(0);
+}
+
+static void
buffer_get_bignum_bits(Buffer *b, BIGNUM *value)
{
u_int bignum_bits = buffer_get_int(b);
@@ -390,29 +461,18 @@ get_line(FILE *fp, char *line, size_t len)
}
static void
-do_convert_from_ssh2(struct passwd *pw)
+do_convert_from_ssh2(struct passwd *pw, Key **k, int *private)
{
- Key *k;
int blen;
u_int len;
char line[1024];
u_char blob[8096];
char encoded[8096];
- struct stat st;
- int escaped = 0, private = 0, ok;
+ int escaped = 0;
FILE *fp;
- if (!have_identity)
- ask_filename(pw, "Enter file in which the key is");
- if (stat(identity_file, &st) < 0) {
- perror(identity_file);
- exit(1);
- }
- fp = fopen(identity_file, "r");
- if (fp == NULL) {
- perror(identity_file);
- exit(1);
- }
+ if ((fp = fopen(identity_file, "r")) == NULL)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
encoded[0] = '\0';
while ((blen = get_line(fp, line, sizeof(line))) != -1) {
if (line[blen - 1] == '\\')
@@ -420,7 +480,7 @@ do_convert_from_ssh2(struct passwd *pw)
if (strncmp(line, "----", 4) == 0 ||
strstr(line, ": ") != NULL) {
if (strstr(line, SSH_COM_PRIVATE_BEGIN) != NULL)
- private = 1;
+ *private = 1;
if (strstr(line, " END ") != NULL) {
break;
}
@@ -445,26 +505,130 @@ do_convert_from_ssh2(struct passwd *pw)
fprintf(stderr, "uudecode failed.\n");
exit(1);
}
- k = private ?
+ *k = *private ?
do_convert_private_ssh2_from_blob(blob, blen) :
key_from_blob(blob, blen);
- if (k == NULL) {
+ if (*k == NULL) {
fprintf(stderr, "decode blob failed.\n");
exit(1);
}
- ok = private ?
- (k->type == KEY_DSA ?
- PEM_write_DSAPrivateKey(stdout, k->dsa, NULL, NULL, 0, NULL, NULL) :
- PEM_write_RSAPrivateKey(stdout, k->rsa, NULL, NULL, 0, NULL, NULL)) :
- key_write(k, stdout);
+ fclose(fp);
+}
+
+static void
+do_convert_from_pkcs8(Key **k, int *private)
+{
+ EVP_PKEY *pubkey;
+ FILE *fp;
+
+ if ((fp = fopen(identity_file, "r")) == NULL)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
+ if ((pubkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL)) == NULL) {
+ fatal("%s: %s is not a recognised public key format", __func__,
+ identity_file);
+ }
+ fclose(fp);
+ switch (EVP_PKEY_type(pubkey->type)) {
+ case EVP_PKEY_RSA:
+ *k = key_new(KEY_UNSPEC);
+ (*k)->type = KEY_RSA;
+ (*k)->rsa = EVP_PKEY_get1_RSA(pubkey);
+ break;
+ case EVP_PKEY_DSA:
+ *k = key_new(KEY_UNSPEC);
+ (*k)->type = KEY_DSA;
+ (*k)->dsa = EVP_PKEY_get1_DSA(pubkey);
+ break;
+ default:
+ fatal("%s: unsupported pubkey type %d", __func__,
+ EVP_PKEY_type(pubkey->type));
+ }
+ EVP_PKEY_free(pubkey);
+ return;
+}
+
+static void
+do_convert_from_pem(Key **k, int *private)
+{
+ FILE *fp;
+ RSA *rsa;
+#ifdef notyet
+ DSA *dsa;
+#endif
+
+ if ((fp = fopen(identity_file, "r")) == NULL)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
+ if ((rsa = PEM_read_RSAPublicKey(fp, NULL, NULL, NULL)) != NULL) {
+ *k = key_new(KEY_UNSPEC);
+ (*k)->type = KEY_RSA;
+ (*k)->rsa = rsa;
+ fclose(fp);
+ return;
+ }
+#if notyet /* OpenSSH 0.9.8 lacks this function */
+ rewind(fp);
+ if ((dsa = PEM_read_DSAPublicKey(fp, NULL, NULL, NULL)) != NULL) {
+ *k = key_new(KEY_UNSPEC);
+ (*k)->type = KEY_DSA;
+ (*k)->dsa = dsa;
+ fclose(fp);
+ return;
+ }
+#endif
+ fatal("%s: unrecognised raw private key format", __func__);
+}
+
+static void
+do_convert_from(struct passwd *pw)
+{
+ Key *k = NULL;
+ int private = 0, ok = 0;
+ struct stat st;
+
+ if (!have_identity)
+ ask_filename(pw, "Enter file in which the key is");
+ if (stat(identity_file, &st) < 0)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
+
+ switch (convert_format) {
+ case FMT_RFC4716:
+ do_convert_from_ssh2(pw, &k, &private);
+ break;
+ case FMT_PKCS8:
+ do_convert_from_pkcs8(&k, &private);
+ break;
+ case FMT_PEM:
+ do_convert_from_pem(&k, &private);
+ break;
+ default:
+ fatal("%s: unknown key format %d", __func__, convert_format);
+ }
+
+ if (!private)
+ ok = key_write(k, stdout);
+ if (ok)
+ fprintf(stdout, "\n");
+ else {
+ switch (k->type) {
+ case KEY_DSA:
+ ok = PEM_write_DSAPrivateKey(stdout, k->dsa, NULL,
+ NULL, 0, NULL, NULL);
+ break;
+ case KEY_RSA:
+ ok = PEM_write_RSAPrivateKey(stdout, k->rsa, NULL,
+ NULL, 0, NULL, NULL);
+ break;
+ default:
+ fatal("%s: unsupported key type %s", __func__,
+ key_type(k));
+ }
+ }
+
if (!ok) {
fprintf(stderr, "key write failed\n");
exit(1);
}
key_free(k);
- if (!private)
- fprintf(stdout, "\n");
- fclose(fp);
exit(0);
}
@@ -493,7 +657,7 @@ do_print_public(struct passwd *pw)
}
static void
-do_download(struct passwd *pw, char *pkcs11provider)
+do_download(struct passwd *pw)
{
#ifdef ENABLE_PKCS11
Key **keys = NULL;
@@ -555,67 +719,68 @@ do_fingerprint(struct passwd *pw)
comment = NULL;
}
- f = fopen(identity_file, "r");
- if (f != NULL) {
- while (fgets(line, sizeof(line), f)) {
- if ((cp = strchr(line, '\n')) == NULL) {
- error("line %d too long: %.40s...",
- num + 1, line);
- skip = 1;
- continue;
- }
- num++;
- if (skip) {
- skip = 0;
- continue;
- }
- *cp = '\0';
+ if ((f = fopen(identity_file, "r")) == NULL)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
- /* Skip leading whitespace, empty and comment lines. */
- for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
- ;
- if (!*cp || *cp == '\n' || *cp == '#')
- continue;
- i = strtol(cp, &ep, 10);
- if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
- int quoted = 0;
- comment = cp;
- for (; *cp && (quoted || (*cp != ' ' &&
- *cp != '\t')); cp++) {
- if (*cp == '\\' && cp[1] == '"')
- cp++; /* Skip both */
- else if (*cp == '"')
- quoted = !quoted;
- }
- if (!*cp)
- continue;
- *cp++ = '\0';
+ while (fgets(line, sizeof(line), f)) {
+ if ((cp = strchr(line, '\n')) == NULL) {
+ error("line %d too long: %.40s...",
+ num + 1, line);
+ skip = 1;
+ continue;
+ }
+ num++;
+ if (skip) {
+ skip = 0;
+ continue;
+ }
+ *cp = '\0';
+
+ /* Skip leading whitespace, empty and comment lines. */
+ for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
+ ;
+ if (!*cp || *cp == '\n' || *cp == '#')
+ continue;
+ i = strtol(cp, &ep, 10);
+ if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) {
+ int quoted = 0;
+ comment = cp;
+ for (; *cp && (quoted || (*cp != ' ' &&
+ *cp != '\t')); cp++) {
+ if (*cp == '\\' && cp[1] == '"')
+ cp++; /* Skip both */
+ else if (*cp == '"')
+ quoted = !quoted;
}
- ep = cp;
- public = key_new(KEY_RSA1);
+ if (!*cp)
+ continue;
+ *cp++ = '\0';
+ }
+ ep = cp;
+ public = key_new(KEY_RSA1);
+ if (key_read(public, &cp) != 1) {
+ cp = ep;
+ key_free(public);
+ public = key_new(KEY_UNSPEC);
if (key_read(public, &cp) != 1) {
- cp = ep;
key_free(public);
- public = key_new(KEY_UNSPEC);
- if (key_read(public, &cp) != 1) {
- key_free(public);
- continue;
- }
+ continue;
}
- comment = *cp ? cp : comment;
- fp = key_fingerprint(public, fptype, rep);
- ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
- printf("%u %s %s (%s)\n", key_size(public), fp,
- comment ? comment : "no comment", key_type(public));
- if (log_level >= SYSLOG_LEVEL_VERBOSE)
- printf("%s\n", ra);
- xfree(ra);
- xfree(fp);
- key_free(public);
- invalid = 0;
}
- fclose(f);
+ comment = *cp ? cp : comment;
+ fp = key_fingerprint(public, fptype, rep);
+ ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART);
+ printf("%u %s %s (%s)\n", key_size(public), fp,
+ comment ? comment : "no comment", key_type(public));
+ if (log_level >= SYSLOG_LEVEL_VERBOSE)
+ printf("%s\n", ra);
+ xfree(ra);
+ xfree(fp);
+ key_free(public);
+ invalid = 0;
}
+ fclose(f);
+
if (invalid) {
printf("%s is not a public key file.\n", identity_file);
exit(1);
@@ -670,7 +835,7 @@ do_known_hosts(struct passwd *pw, const char *name)
have_identity = 1;
}
if ((in = fopen(identity_file, "r")) == NULL)
- fatal("fopen: %s", strerror(errno));
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
/*
* Find hosts goes to stdout, hash and deletions happen in-place
@@ -1104,7 +1269,7 @@ fmt_validity(u_int64_t valid_from, u_int64_t valid_to)
}
static void
-add_flag_constraint(Buffer *c, const char *name)
+add_flag_option(Buffer *c, const char *name)
{
debug3("%s: %s", __func__, name);
buffer_put_cstring(c, name);
@@ -1112,7 +1277,7 @@ add_flag_constraint(Buffer *c, const char *name)
}
static void
-add_string_constraint(Buffer *c, const char *name, const char *value)
+add_string_option(Buffer *c, const char *name, const char *value)
{
Buffer b;
@@ -1126,25 +1291,62 @@ add_string_constraint(Buffer *c, const char *name, const char *value)
buffer_free(&b);
}
+#define OPTIONS_CRITICAL 1
+#define OPTIONS_EXTENSIONS 2
static void
-prepare_constraint_buf(Buffer *c)
+prepare_options_buf(Buffer *c, int which)
{
-
buffer_clear(c);
- if ((constraint_flags & CONSTRAINT_X_FWD) != 0)
- add_flag_constraint(c, "permit-X11-forwarding");
- if ((constraint_flags & CONSTRAINT_AGENT_FWD) != 0)
- add_flag_constraint(c, "permit-agent-forwarding");
- if ((constraint_flags & CONSTRAINT_PORT_FWD) != 0)
- add_flag_constraint(c, "permit-port-forwarding");
- if ((constraint_flags & CONSTRAINT_PTY) != 0)
- add_flag_constraint(c, "permit-pty");
- if ((constraint_flags & CONSTRAINT_USER_RC) != 0)
- add_flag_constraint(c, "permit-user-rc");
- if (constraint_command != NULL)
- add_string_constraint(c, "force-command", constraint_command);
- if (constraint_src_addr != NULL)
- add_string_constraint(c, "source-address", constraint_src_addr);
+ if ((which & OPTIONS_CRITICAL) != 0 &&
+ certflags_command != NULL)
+ add_string_option(c, "force-command", certflags_command);
+ if ((which & OPTIONS_EXTENSIONS) != 0 &&
+ (certflags_flags & CERTOPT_AGENT_FWD) != 0)
+ add_flag_option(c, "permit-agent-forwarding");
+ if ((which & OPTIONS_EXTENSIONS) != 0 &&
+ (certflags_flags & CERTOPT_PORT_FWD) != 0)
+ add_flag_option(c, "permit-port-forwarding");
+ if ((which & OPTIONS_EXTENSIONS) != 0 &&
+ (certflags_flags & CERTOPT_PTY) != 0)
+ add_flag_option(c, "permit-pty");
+ if ((which & OPTIONS_EXTENSIONS) != 0 &&
+ (certflags_flags & CERTOPT_USER_RC) != 0)
+ add_flag_option(c, "permit-user-rc");
+ if ((which & OPTIONS_EXTENSIONS) != 0 &&
+ (certflags_flags & CERTOPT_X_FWD) != 0)
+ add_flag_option(c, "permit-X11-forwarding");
+ if ((which & OPTIONS_CRITICAL) != 0 &&
+ certflags_src_addr != NULL)
+ add_string_option(c, "source-address", certflags_src_addr);
+}
+
+static Key *
+load_pkcs11_key(char *path)
+{
+#ifdef ENABLE_PKCS11
+ Key **keys = NULL, *public, *private = NULL;
+ int i, nkeys;
+
+ if ((public = key_load_public(path, NULL)) == NULL)
+ fatal("Couldn't load CA public key \"%s\"", path);
+
+ nkeys = pkcs11_add_provider(pkcs11provider, identity_passphrase, &keys);
+ debug3("%s: %d keys", __func__, nkeys);
+ if (nkeys <= 0)
+ fatal("cannot read public key from pkcs11");
+ for (i = 0; i < nkeys; i++) {
+ if (key_equal_public(public, keys[i])) {
+ private = keys[i];
+ continue;
+ }
+ key_free(keys[i]);
+ }
+ xfree(keys);
+ key_free(public);
+ return private;
+#else
+ fatal("no pkcs11 support");
+#endif /* ENABLE_PKCS11 */
}
static void
@@ -1155,9 +1357,33 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
Key *ca, *public;
char *otmp, *tmp, *cp, *out, *comment, **plist = NULL;
FILE *f;
+ int v00 = 0; /* legacy keys */
+
+ if (key_type_name != NULL) {
+ switch (key_type_from_name(key_type_name)) {
+ case KEY_RSA_CERT_V00:
+ case KEY_DSA_CERT_V00:
+ v00 = 1;
+ break;
+ case KEY_UNSPEC:
+ if (strcasecmp(key_type_name, "v00") == 0) {
+ v00 = 1;
+ break;
+ } else if (strcasecmp(key_type_name, "v01") == 0)
+ break;
+ /* FALLTHROUGH */
+ default:
+ fprintf(stderr, "unknown key type %s\n", key_type_name);
+ exit(1);
+ }
+ }
+ pkcs11_init(1);
tmp = tilde_expand_filename(ca_key_path, pw->pw_uid);
- if ((ca = load_identity(tmp)) == NULL)
+ if (pkcs11provider != NULL) {
+ if ((ca = load_pkcs11_key(tmp)) == NULL)
+ fatal("No PKCS#11 key matching %s found", ca_key_path);
+ } else if ((ca = load_identity(tmp)) == NULL)
fatal("Couldn't load CA key \"%s\"", tmp);
xfree(tmp);
@@ -1183,15 +1409,24 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
__func__, tmp, key_type(public));
/* Prepare certificate to sign */
- if (key_to_certified(public) != 0)
+ if (key_to_certified(public, v00) != 0)
fatal("Could not upgrade key %s to certificate", tmp);
public->cert->type = cert_key_type;
+ public->cert->serial = (u_int64_t)cert_serial;
public->cert->key_id = xstrdup(cert_key_id);
public->cert->nprincipals = n;
public->cert->principals = plist;
public->cert->valid_after = cert_valid_from;
public->cert->valid_before = cert_valid_to;
- prepare_constraint_buf(&public->cert->constraints);
+ if (v00) {
+ prepare_options_buf(&public->cert->critical,
+ OPTIONS_CRITICAL|OPTIONS_EXTENSIONS);
+ } else {
+ prepare_options_buf(&public->cert->critical,
+ OPTIONS_CRITICAL);
+ prepare_options_buf(&public->cert->extensions,
+ OPTIONS_EXTENSIONS);
+ }
public->cert->signature_key = key_from_private(ca);
if (key_certify(public, ca) != 0)
@@ -1212,17 +1447,19 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
fprintf(f, " %s\n", comment);
fclose(f);
- if (!quiet)
- logit("Signed %s key %s: id \"%s\"%s%s valid %s",
- cert_key_type == SSH2_CERT_TYPE_USER?"user":"host",
- out, cert_key_id,
+ if (!quiet) {
+ logit("Signed %s key %s: id \"%s\" serial %llu%s%s "
+ "valid %s", key_cert_type(public),
+ out, public->cert->key_id, public->cert->serial,
cert_principals != NULL ? " for " : "",
cert_principals != NULL ? cert_principals : "",
fmt_validity(cert_valid_from, cert_valid_to));
+ }
key_free(public);
xfree(out);
}
+ pkcs11_terminate();
exit(0);
}
@@ -1321,50 +1558,92 @@ parse_cert_times(char *timespec)
}
static void
-add_cert_constraint(char *opt)
+add_cert_option(char *opt)
{
char *val;
if (strcmp(opt, "clear") == 0)
- constraint_flags = 0;
+ certflags_flags = 0;
else if (strcasecmp(opt, "no-x11-forwarding") == 0)
- constraint_flags &= ~CONSTRAINT_X_FWD;
+ certflags_flags &= ~CERTOPT_X_FWD;
else if (strcasecmp(opt, "permit-x11-forwarding") == 0)
- constraint_flags |= CONSTRAINT_X_FWD;
+ certflags_flags |= CERTOPT_X_FWD;
else if (strcasecmp(opt, "no-agent-forwarding") == 0)
- constraint_flags &= ~CONSTRAINT_AGENT_FWD;
+ certflags_flags &= ~CERTOPT_AGENT_FWD;
else if (strcasecmp(opt, "permit-agent-forwarding") == 0)
- constraint_flags |= CONSTRAINT_AGENT_FWD;
+ certflags_flags |= CERTOPT_AGENT_FWD;
else if (strcasecmp(opt, "no-port-forwarding") == 0)
- constraint_flags &= ~CONSTRAINT_PORT_FWD;
+ certflags_flags &= ~CERTOPT_PORT_FWD;
else if (strcasecmp(opt, "permit-port-forwarding") == 0)
- constraint_flags |= CONSTRAINT_PORT_FWD;
+ certflags_flags |= CERTOPT_PORT_FWD;
else if (strcasecmp(opt, "no-pty") == 0)
- constraint_flags &= ~CONSTRAINT_PTY;
+ certflags_flags &= ~CERTOPT_PTY;
else if (strcasecmp(opt, "permit-pty") == 0)
- constraint_flags |= CONSTRAINT_PTY;
+ certflags_flags |= CERTOPT_PTY;
else if (strcasecmp(opt, "no-user-rc") == 0)
- constraint_flags &= ~CONSTRAINT_USER_RC;
+ certflags_flags &= ~CERTOPT_USER_RC;
else if (strcasecmp(opt, "permit-user-rc") == 0)
- constraint_flags |= CONSTRAINT_USER_RC;
+ certflags_flags |= CERTOPT_USER_RC;
else if (strncasecmp(opt, "force-command=", 14) == 0) {
val = opt + 14;
if (*val == '\0')
- fatal("Empty force-command constraint");
- if (constraint_command != NULL)
+ fatal("Empty force-command option");
+ if (certflags_command != NULL)
fatal("force-command already specified");
- constraint_command = xstrdup(val);
+ certflags_command = xstrdup(val);
} else if (strncasecmp(opt, "source-address=", 15) == 0) {
val = opt + 15;
if (*val == '\0')
- fatal("Empty source-address constraint");
- if (constraint_src_addr != NULL)
+ fatal("Empty source-address option");
+ if (certflags_src_addr != NULL)
fatal("source-address already specified");
if (addr_match_cidr_list(NULL, val) != 0)
fatal("Invalid source-address list");
- constraint_src_addr = xstrdup(val);
+ certflags_src_addr = xstrdup(val);
} else
- fatal("Unsupported certificate constraint \"%s\"", opt);
+ fatal("Unsupported certificate option \"%s\"", opt);
+}
+
+static void
+show_options(const Buffer *optbuf, int v00, int in_critical)
+{
+ u_char *name, *data;
+ u_int dlen;
+ Buffer options, option;
+
+ buffer_init(&options);
+ buffer_append(&options, buffer_ptr(optbuf), buffer_len(optbuf));
+
+ buffer_init(&option);
+ while (buffer_len(&options) != 0) {
+ name = buffer_get_string(&options, NULL);
+ data = buffer_get_string_ptr(&options, &dlen);
+ buffer_append(&option, data, dlen);
+ printf(" %s", name);
+ if ((v00 || !in_critical) &&
+ (strcmp(name, "permit-X11-forwarding") == 0 ||
+ strcmp(name, "permit-agent-forwarding") == 0 ||
+ strcmp(name, "permit-port-forwarding") == 0 ||
+ strcmp(name, "permit-pty") == 0 ||
+ strcmp(name, "permit-user-rc") == 0))
+ printf("\n");
+ else if ((v00 || in_critical) &&
+ (strcmp(name, "force-command") == 0 ||
+ strcmp(name, "source-address") == 0)) {
+ data = buffer_get_string(&option, NULL);
+ printf(" %s\n", data);
+ xfree(data);
+ } else {
+ printf(" UNKNOWN OPTION (len %u)\n",
+ buffer_len(&option));
+ buffer_clear(&option);
+ }
+ xfree(name);
+ if (buffer_len(&option) != 0)
+ fatal("Option corrupt: extra data at end");
+ }
+ buffer_free(&option);
+ buffer_free(&options);
}
static void
@@ -1373,31 +1652,31 @@ do_show_cert(struct passwd *pw)
Key *key;
struct stat st;
char *key_fp, *ca_fp;
- Buffer constraints, constraint;
- u_char *name, *data;
- u_int i, dlen;
+ u_int i, v00;
if (!have_identity)
ask_filename(pw, "Enter file in which the key is");
- if (stat(identity_file, &st) < 0) {
- perror(identity_file);
- exit(1);
- }
+ if (stat(identity_file, &st) < 0)
+ fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
if ((key = key_load_public(identity_file, NULL)) == NULL)
fatal("%s is not a public key", identity_file);
if (!key_is_cert(key))
fatal("%s is not a certificate", identity_file);
-
+ v00 = key->type == KEY_RSA_CERT_V00 || key->type == KEY_DSA_CERT_V00;
+
key_fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX);
ca_fp = key_fingerprint(key->cert->signature_key,
SSH_FP_MD5, SSH_FP_HEX);
printf("%s:\n", identity_file);
- printf(" %s %s certificate %s\n", key_type(key),
- key_cert_type(key), key_fp);
- printf(" Signed by %s CA %s\n",
+ printf(" Type: %s %s certificate\n", key_ssh_name(key),
+ key_cert_type(key));
+ printf(" Public key: %s %s\n", key_type(key), key_fp);
+ printf(" Signing CA: %s %s\n",
key_type(key->cert->signature_key), ca_fp);
- printf(" Key ID \"%s\"\n", key->cert->key_id);
+ printf(" Key ID: \"%s\"\n", key->cert->key_id);
+ if (!v00)
+ printf(" Serial: %llu\n", key->cert->serial);
printf(" Valid: %s\n",
fmt_validity(key->cert->valid_after, key->cert->valid_before));
printf(" Principals: ");
@@ -1409,45 +1688,22 @@ do_show_cert(struct passwd *pw)
key->cert->principals[i]);
printf("\n");
}
- printf(" Constraints: ");
- if (buffer_len(&key->cert->constraints) == 0)
+ printf(" Critical Options: ");
+ if (buffer_len(&key->cert->critical) == 0)
printf("(none)\n");
else {
printf("\n");
- buffer_init(&constraints);
- buffer_append(&constraints,
- buffer_ptr(&key->cert->constraints),
- buffer_len(&key->cert->constraints));
- buffer_init(&constraint);
- while (buffer_len(&constraints) != 0) {
- name = buffer_get_string(&constraints, NULL);
- data = buffer_get_string_ptr(&constraints, &dlen);
- buffer_append(&constraint, data, dlen);
- printf(" %s", name);
- if (strcmp(name, "permit-X11-forwarding") == 0 ||
- strcmp(name, "permit-agent-forwarding") == 0 ||
- strcmp(name, "permit-port-forwarding") == 0 ||
- strcmp(name, "permit-pty") == 0 ||
- strcmp(name, "permit-user-rc") == 0)
- printf("\n");
- else if (strcmp(name, "force-command") == 0 ||
- strcmp(name, "source-address") == 0) {
- data = buffer_get_string(&constraint, NULL);
- printf(" %s\n", data);
- xfree(data);
- } else {
- printf(" UNKNOWN CONSTRAINT (len %u)\n",
- buffer_len(&constraint));
- buffer_clear(&constraint);
- }
- xfree(name);
- if (buffer_len(&constraint) != 0)
- fatal("Constraint corrupt: extra data at end");
+ show_options(&key->cert->critical, v00, 1);
+ }
+ if (!v00) {
+ printf(" Extensions: ");
+ if (buffer_len(&key->cert->extensions) == 0)
+ printf("(none)\n");
+ else {
+ printf("\n");
+ show_options(&key->cert->extensions, v00, 0);
}
- buffer_free(&constraint);
- buffer_free(&constraints);
}
-
exit(0);
}
@@ -1464,7 +1720,7 @@ usage(void)
#ifdef ENABLE_PKCS11
fprintf(stderr, " -D pkcs11 Download public key from pkcs11 token.\n");
#endif
- fprintf(stderr, " -e Convert OpenSSH to RFC 4716 key file.\n");
+ fprintf(stderr, " -e Export OpenSSH to foreign format key file.\n");
fprintf(stderr, " -F hostname Find hostname in known hosts file.\n");
fprintf(stderr, " -f filename Filename of the key file.\n");
fprintf(stderr, " -G file Generate candidates for DH-GEX moduli.\n");
@@ -1472,26 +1728,28 @@ usage(void)
fprintf(stderr, " -H Hash names in known_hosts file.\n");
fprintf(stderr, " -h Generate host certificate instead of a user certificate.\n");
fprintf(stderr, " -I key_id Key identifier to include in certificate.\n");
- fprintf(stderr, " -i Convert RFC 4716 to OpenSSH key file.\n");
+ fprintf(stderr, " -i Import foreign format to OpenSSH key file.\n");
fprintf(stderr, " -L Print the contents of a certificate.\n");
fprintf(stderr, " -l Show fingerprint of key file.\n");
fprintf(stderr, " -M memory Amount of memory (MB) to use for generating DH-GEX moduli.\n");
- fprintf(stderr, " -n name,... User/host principal names to include in certificate\n");
+ fprintf(stderr, " -m key_fmt Conversion format for -e/-i (PEM|PKCS8|RFC4716).\n");
fprintf(stderr, " -N phrase Provide new passphrase.\n");
- fprintf(stderr, " -O cnstr Specify a certificate constraint.\n");
+ fprintf(stderr, " -n name,... User/host principal names to include in certificate\n");
+ fprintf(stderr, " -O option Specify a certificate option.\n");
fprintf(stderr, " -P phrase Provide old passphrase.\n");
fprintf(stderr, " -p Change passphrase of private key file.\n");
fprintf(stderr, " -q Quiet.\n");
fprintf(stderr, " -R hostname Remove host from known_hosts file.\n");
fprintf(stderr, " -r hostname Print DNS resource record.\n");
- fprintf(stderr, " -s ca_key Certify keys with CA key.\n");
fprintf(stderr, " -S start Start point (hex) for generating DH-GEX moduli.\n");
+ fprintf(stderr, " -s ca_key Certify keys with CA key.\n");
fprintf(stderr, " -T file Screen candidates for DH-GEX moduli.\n");
fprintf(stderr, " -t type Specify type of key to create.\n");
fprintf(stderr, " -V from:to Specify certificate validity interval.\n");
fprintf(stderr, " -v Verbose.\n");
fprintf(stderr, " -W gen Generator to use for generating DH-GEX moduli.\n");
fprintf(stderr, " -y Read private key file and print public key.\n");
+ fprintf(stderr, " -z serial Specify a serial number.\n");
exit(1);
}
@@ -1503,12 +1761,12 @@ int
main(int argc, char **argv)
{
char dotsshdir[MAXPATHLEN], comment[1024], *passphrase1, *passphrase2;
- char out_file[MAXPATHLEN], *pkcs11provider = NULL;
- char *rr_hostname = NULL;
+ char out_file[MAXPATHLEN], *rr_hostname = NULL;
Key *private, *public;
struct passwd *pw;
struct stat st;
int opt, type, fd;
+ u_int maxbits;
u_int32_t memory = 0, generator_wanted = 0, trials = 100;
int do_gen_candidates = 0, do_screen_candidates = 0;
BIGNUM *start = NULL;
@@ -1540,8 +1798,8 @@ main(int argc, char **argv)
exit(1);
}
- while ((opt = getopt(argc, argv, "degiqpclBHLhvxXyF:b:f:t:D:I:P:N:n:"
- "O:C:r:g:R:T:G:M:S:s:a:V:W:")) != -1) {
+ while ((opt = getopt(argc, argv, "degiqpclBHLhvxXyF:b:f:t:D:I:P:m:N:n:"
+ "O:C:r:g:R:T:G:M:S:s:a:V:W:z:")) != -1) {
switch (opt) {
case 'b':
bits = (u_int32_t)strtonum(optarg, 768, 32768, &errstr);
@@ -1572,6 +1830,21 @@ main(int argc, char **argv)
case 'B':
print_bubblebabble = 1;
break;
+ case 'm':
+ if (strcasecmp(optarg, "RFC4716") == 0 ||
+ strcasecmp(optarg, "ssh2") == 0) {
+ convert_format = FMT_RFC4716;
+ break;
+ }
+ if (strcasecmp(optarg, "PKCS8") == 0) {
+ convert_format = FMT_PKCS8;
+ break;
+ }
+ if (strcasecmp(optarg, "PEM") == 0) {
+ convert_format = FMT_PEM;
+ break;
+ }
+ fatal("Unsupported conversion format \"%s\"", optarg);
case 'n':
cert_principals = optarg;
break;
@@ -1597,7 +1870,7 @@ main(int argc, char **argv)
identity_new_passphrase = optarg;
break;
case 'O':
- add_cert_constraint(optarg);
+ add_cert_option(optarg);
break;
case 'C':
identity_comment = optarg;
@@ -1608,16 +1881,16 @@ main(int argc, char **argv)
case 'e':
case 'x':
/* export key */
- convert_to_ssh2 = 1;
+ convert_to = 1;
break;
case 'h':
cert_key_type = SSH2_CERT_TYPE_HOST;
- constraint_flags = 0;
+ certflags_flags = 0;
break;
case 'i':
case 'X':
/* import key */
- convert_from_ssh2 = 1;
+ convert_from = 1;
break;
case 'y':
print_public = 1;
@@ -1661,9 +1934,8 @@ main(int argc, char **argv)
break;
case 'M':
memory = (u_int32_t)strtonum(optarg, 1, UINT_MAX, &errstr);
- if (errstr) {
+ if (errstr)
fatal("Memory limit is %s: %s", errstr, optarg);
- }
break;
case 'G':
do_gen_candidates = 1;
@@ -1685,6 +1957,11 @@ main(int argc, char **argv)
case 'V':
parse_cert_times(optarg);
break;
+ case 'z':
+ cert_serial = strtonum(optarg, 0, LLONG_MAX, &errstr);
+ if (errstr)
+ fatal("Invalid serial number: %s", errstr);
+ break;
case '?':
default:
usage();
@@ -1729,10 +2006,10 @@ main(int argc, char **argv)
do_change_passphrase(pw);
if (change_comment)
do_change_comment(pw);
- if (convert_to_ssh2)
- do_convert_to_ssh2(pw);
- if (convert_from_ssh2)
- do_convert_from_ssh2(pw);
+ if (convert_to)
+ do_convert_to(pw);
+ if (convert_from)
+ do_convert_from(pw);
if (print_public)
do_print_public(pw);
if (rr_hostname != NULL) {
@@ -1759,7 +2036,7 @@ main(int argc, char **argv)
}
}
if (pkcs11provider != NULL)
- do_download(pw, pkcs11provider);
+ do_download(pw);
if (do_gen_candidates) {
FILE *out = fopen(out_file, "w");
@@ -1811,6 +2088,12 @@ main(int argc, char **argv)
}
if (bits == 0)
bits = (type == KEY_DSA) ? DEFAULT_BITS_DSA : DEFAULT_BITS;
+ maxbits = (type == KEY_DSA) ?
+ OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS;
+ if (bits > maxbits) {
+ fprintf(stderr, "key bits exceeds maximum %d\n", maxbits);
+ exit(1);
+ }
if (type == KEY_DSA && bits != 1024)
fatal("DSA keys must be 1024 bits");
if (!quiet)
@@ -1826,13 +2109,19 @@ main(int argc, char **argv)
ask_filename(pw, "Enter file in which to save the key");
/* Create ~/.ssh directory if it doesn't already exist. */
- snprintf(dotsshdir, sizeof dotsshdir, "%s/%s", pw->pw_dir, _PATH_SSH_USER_DIR);
- if (strstr(identity_file, dotsshdir) != NULL &&
- stat(dotsshdir, &st) < 0) {
- if (mkdir(dotsshdir, 0700) < 0)
- error("Could not create directory '%s'.", dotsshdir);
- else if (!quiet)
- printf("Created directory '%s'.\n", dotsshdir);
+ snprintf(dotsshdir, sizeof dotsshdir, "%s/%s",
+ pw->pw_dir, _PATH_SSH_USER_DIR);
+ if (strstr(identity_file, dotsshdir) != NULL) {
+ if (stat(dotsshdir, &st) < 0) {
+ if (errno != ENOENT) {
+ error("Could not stat %s: %s", dotsshdir,
+ strerror(errno));
+ } else if (mkdir(dotsshdir, 0700) < 0) {
+ error("Could not create directory '%s': %s",
+ dotsshdir, strerror(errno));
+ } else if (!quiet)
+ printf("Created directory '%s'.\n", dotsshdir);
+ }
}
/* If the file already exists, ask the user to confirm. */
if (stat(identity_file, &st) >= 0) {
diff --git a/crypto/openssh/ssh-keyscan.c b/crypto/openssh/ssh-keyscan.c
index 7afe446..b6cf427 100644
--- a/crypto/openssh/ssh-keyscan.c
+++ b/crypto/openssh/ssh-keyscan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keyscan.c,v 1.81 2010/01/09 23:04:13 dtucker Exp $ */
+/* $OpenBSD: ssh-keyscan.c,v 1.82 2010/06/22 04:54:30 djm Exp $ */
/*
* Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
*
@@ -104,122 +104,6 @@ typedef struct Connection {
TAILQ_HEAD(conlist, Connection) tq; /* Timeout Queue */
con *fdcon;
-/*
- * This is just a wrapper around fgets() to make it usable.
- */
-
-/* Stress-test. Increase this later. */
-#define LINEBUF_SIZE 16
-
-typedef struct {
- char *buf;
- u_int size;
- int lineno;
- const char *filename;
- FILE *stream;
- void (*errfun) (const char *,...);
-} Linebuf;
-
-static Linebuf *
-Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
-{
- Linebuf *lb;
-
- if (!(lb = malloc(sizeof(*lb)))) {
- if (errfun)
- (*errfun) ("linebuf (%s): malloc failed\n",
- filename ? filename : "(stdin)");
- return (NULL);
- }
- if (filename) {
- lb->filename = filename;
- if (!(lb->stream = fopen(filename, "r"))) {
- xfree(lb);
- if (errfun)
- (*errfun) ("%s: %s\n", filename, strerror(errno));
- return (NULL);
- }
- } else {
- lb->filename = "(stdin)";
- lb->stream = stdin;
- }
-
- if (!(lb->buf = malloc((lb->size = LINEBUF_SIZE)))) {
- if (errfun)
- (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
- xfree(lb);
- return (NULL);
- }
- lb->errfun = errfun;
- lb->lineno = 0;
- return (lb);
-}
-
-static void
-Linebuf_free(Linebuf * lb)
-{
- fclose(lb->stream);
- xfree(lb->buf);
- xfree(lb);
-}
-
-#if 0
-static void
-Linebuf_restart(Linebuf * lb)
-{
- clearerr(lb->stream);
- rewind(lb->stream);
- lb->lineno = 0;
-}
-
-static int
-Linebuf_lineno(Linebuf * lb)
-{
- return (lb->lineno);
-}
-#endif
-
-static char *
-Linebuf_getline(Linebuf * lb)
-{
- size_t n = 0;
- void *p;
-
- lb->lineno++;
- for (;;) {
- /* Read a line */
- if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) {
- if (ferror(lb->stream) && lb->errfun)
- (*lb->errfun)("%s: %s\n", lb->filename,
- strerror(errno));
- return (NULL);
- }
- n = strlen(lb->buf);
-
- /* Return it or an error if it fits */
- if (n > 0 && lb->buf[n - 1] == '\n') {
- lb->buf[n - 1] = '\0';
- return (lb->buf);
- }
- if (n != lb->size - 1) {
- if (lb->errfun)
- (*lb->errfun)("%s: skipping incomplete last line\n",
- lb->filename);
- return (NULL);
- }
- /* Double the buffer if we need more space */
- lb->size *= 2;
- if ((p = realloc(lb->buf, lb->size)) == NULL) {
- lb->size /= 2;
- if (lb->errfun)
- (*lb->errfun)("linebuf (%s): realloc failed\n",
- lb->filename);
- return (NULL);
- }
- lb->buf = p;
- }
-}
-
static int
fdlim_get(int hard)
{
@@ -724,8 +608,10 @@ int
main(int argc, char **argv)
{
int debug_flag = 0, log_level = SYSLOG_LEVEL_INFO;
- int opt, fopt_count = 0;
- char *tname;
+ int opt, fopt_count = 0, j;
+ char *tname, *cp, line[NI_MAXHOST];
+ FILE *fp;
+ u_long linenum;
extern int optind;
extern char *optarg;
@@ -826,19 +712,40 @@ main(int argc, char **argv)
read_wait_nfdset = howmany(maxfd, NFDBITS);
read_wait = xcalloc(read_wait_nfdset, sizeof(fd_mask));
- if (fopt_count) {
- Linebuf *lb;
- char *line;
- int j;
+ for (j = 0; j < fopt_count; j++) {
+ if (argv[j] == NULL)
+ fp = stdin;
+ else if ((fp = fopen(argv[j], "r")) == NULL)
+ fatal("%s: %s: %s", __progname, argv[j],
+ strerror(errno));
+ linenum = 0;
+
+ while (read_keyfile_line(fp,
+ argv[j] == NULL ? "(stdin)" : argv[j], line, sizeof(line),
+ &linenum) != -1) {
+ /* Chomp off trailing whitespace and comments */
+ if ((cp = strchr(line, '#')) == NULL)
+ cp = line + strlen(line) - 1;
+ while (cp >= line) {
+ if (*cp == ' ' || *cp == '\t' ||
+ *cp == '\n' || *cp == '#')
+ *cp-- = '\0';
+ else
+ break;
+ }
- for (j = 0; j < fopt_count; j++) {
- lb = Linebuf_alloc(argv[j], error);
- if (!lb)
+ /* Skip empty lines */
+ if (*line == '\0')
continue;
- while ((line = Linebuf_getline(lb)) != NULL)
- do_host(line);
- Linebuf_free(lb);
+
+ do_host(line);
}
+
+ if (ferror(fp))
+ fatal("%s: %s: %s", __progname, argv[j],
+ strerror(errno));
+
+ fclose(fp);
}
while (optind < argc)
diff --git a/crypto/openssh/ssh-keysign.8 b/crypto/openssh/ssh-keysign.8
index 40aaca2..abee1ea 100644
--- a/crypto/openssh/ssh-keysign.8
+++ b/crypto/openssh/ssh-keysign.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ssh-keysign.8,v 1.9 2007/05/31 19:20:16 jmc Exp $
+.\" $OpenBSD: ssh-keysign.8,v 1.10 2010/08/04 05:42:47 djm Exp $
.\"
.\" Copyright (c) 2002 Markus Friedl. All rights reserved.
.\"
@@ -22,7 +22,7 @@
.\" (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 May 31, 2007
+.Dd August 4, 2010
.Dt SSH-KEYSIGN 8
.Os
.Sh NAME
@@ -68,6 +68,9 @@ accessible to others.
Since they are readable only by root,
.Nm
must be set-uid root if host-based authentication is used.
+.It Pa /etc/ssh/ssh_host_dsa_key-cert.pub, /etc/ssh/ssh_host_rsa_key-cert.pub
+If these files exist they are assumed to contain public certificate
+information corresponding with the private keys above.
.El
.Sh SEE ALSO
.Xr ssh 1 ,
diff --git a/crypto/openssh/ssh-keysign.c b/crypto/openssh/ssh-keysign.c
index 0fdcebb..0c70770 100644
--- a/crypto/openssh/ssh-keysign.c
+++ b/crypto/openssh/ssh-keysign.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keysign.c,v 1.30 2010/01/13 01:20:20 dtucker Exp $ */
+/* $OpenBSD: ssh-keysign.c,v 1.32 2010/08/04 06:08:40 djm Exp $ */
/*
* Copyright (c) 2002 Markus Friedl. All rights reserved.
*
@@ -232,7 +232,7 @@ main(int argc, char **argv)
found = 0;
for (i = 0; i < 2; i++) {
if (keys[i] != NULL &&
- key_equal(key, keys[i])) {
+ key_equal_public(key, keys[i])) {
found = 1;
break;
}
diff --git a/crypto/openssh/ssh-pkcs11-helper.0 b/crypto/openssh/ssh-pkcs11-helper.0
deleted file mode 100644
index 2760cad..0000000
--- a/crypto/openssh/ssh-pkcs11-helper.0
+++ /dev/null
@@ -1,25 +0,0 @@
-SSH-PKCS11-HELPER(8) OpenBSD System Manager's Manual SSH-PKCS11-HELPER(8)
-
-NAME
- ssh-pkcs11-helper - ssh-agent helper program for PKCS#11 support
-
-SYNOPSIS
- ssh-pkcs11-helper
-
-DESCRIPTION
- ssh-pkcs11-helper is used by ssh-agent(1) to access keys provided by a
- PKCS#11 token.
-
- ssh-pkcs11-helper is not intended to be invoked by the user, but from
- ssh-agent(1).
-
-SEE ALSO
- ssh(1), ssh-add(1), ssh-agent(1)
-
-HISTORY
- ssh-pkcs11-helper first appeared in OpenBSD 4.7.
-
-AUTHORS
- Markus Friedl <markus@openbsd.org>
-
-OpenBSD 4.6 February 10, 2010 1
diff --git a/crypto/openssh/ssh-pkcs11.c b/crypto/openssh/ssh-pkcs11.c
index f0192dc..286c232 100644
--- a/crypto/openssh/ssh-pkcs11.c
+++ b/crypto/openssh/ssh-pkcs11.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-pkcs11.c,v 1.4 2010/02/24 06:12:53 djm Exp $ */
+/* $OpenBSD: ssh-pkcs11.c,v 1.6 2010/06/08 21:32:19 markus Exp $ */
/*
* Copyright (c) 2010 Markus Friedl. All rights reserved.
*
@@ -187,6 +187,34 @@ pkcs11_rsa_finish(RSA *rsa)
return (rv);
}
+/* find a single 'obj' for given attributes */
+static int
+pkcs11_find(struct pkcs11_provider *p, CK_ULONG slotidx, CK_ATTRIBUTE *attr,
+ CK_ULONG nattr, CK_OBJECT_HANDLE *obj)
+{
+ CK_FUNCTION_LIST *f;
+ CK_SESSION_HANDLE session;
+ CK_ULONG nfound = 0;
+ CK_RV rv;
+ int ret = -1;
+
+ f = p->function_list;
+ session = p->slotinfo[slotidx].session;
+ if ((rv = f->C_FindObjectsInit(session, attr, nattr)) != CKR_OK) {
+ error("C_FindObjectsInit failed (nattr %lu): %lu", nattr, rv);
+ return (-1);
+ }
+ if ((rv = f->C_FindObjects(session, obj, 1, &nfound)) != CKR_OK ||
+ nfound != 1) {
+ debug("C_FindObjects failed (nfound %lu nattr %lu): %lu",
+ nfound, nattr, rv);
+ } else
+ ret = 0;
+ if ((rv = f->C_FindObjectsFinal(session)) != CKR_OK)
+ error("C_FindObjectsFinal failed: %lu", rv);
+ return (ret);
+}
+
/* openssl callback doing the actual signing operation */
static int
pkcs11_rsa_private_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa,
@@ -196,7 +224,7 @@ pkcs11_rsa_private_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa,
struct pkcs11_slotinfo *si;
CK_FUNCTION_LIST *f;
CK_OBJECT_HANDLE obj;
- CK_ULONG tlen = 0, nfound = 0;
+ CK_ULONG tlen = 0;
CK_RV rv;
CK_OBJECT_CLASS private_key_class = CKO_PRIVATE_KEY;
CK_BBOOL true_val = CK_TRUE;
@@ -247,13 +275,10 @@ pkcs11_rsa_private_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa,
}
key_filter[1].pValue = k11->keyid;
key_filter[1].ulValueLen = k11->keyid_len;
- if ((rv = f->C_FindObjectsInit(si->session, key_filter, 3)) != CKR_OK) {
- error("C_FindObjectsInit failed: %lu", rv);
- return (-1);
- }
- if ((rv = f->C_FindObjects(si->session, &obj, 1, &nfound)) != CKR_OK ||
- nfound != 1) {
- error("C_FindObjects failed (%lu nfound): %lu", nfound, rv);
+ /* try to find object w/CKA_SIGN first, retry w/o */
+ if (pkcs11_find(k11->provider, k11->slotidx, key_filter, 3, &obj) < 0 &&
+ pkcs11_find(k11->provider, k11->slotidx, key_filter, 2, &obj) < 0) {
+ error("cannot find private key");
} else if ((rv = f->C_SignInit(si->session, &mech, obj)) != CKR_OK) {
error("C_SignInit failed: %lu", rv);
} else {
@@ -265,8 +290,6 @@ pkcs11_rsa_private_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa,
else
error("C_Sign failed: %lu", rv);
}
- if ((rv = f->C_FindObjectsFinal(si->session)) != CKR_OK)
- error("C_FindObjectsFinal failed: %lu", rv);
return (rval);
}
@@ -410,7 +433,13 @@ pkcs11_fetch_keys(struct pkcs11_provider *p, CK_ULONG slotidx, Key ***keysp,
error("C_GetAttributeValue failed: %lu", rv);
continue;
}
- /* allocate buffers for attributes, XXX check ulValueLen? */
+ /* check that none of the attributes are zero length */
+ if (attribs[0].ulValueLen == 0 ||
+ attribs[1].ulValueLen == 0 ||
+ attribs[2].ulValueLen == 0) {
+ continue;
+ }
+ /* allocate buffers for attributes */
for (i = 0; i < 3; i++)
attribs[i].pValue = xmalloc(attribs[i].ulValueLen);
/* retrieve ID, modulus and public exponent of RSA key */
diff --git a/crypto/openssh/ssh-rsa.c b/crypto/openssh/ssh-rsa.c
index 842857f..c471ff3 100644
--- a/crypto/openssh/ssh-rsa.c
+++ b/crypto/openssh/ssh-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-rsa.c,v 1.40 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: ssh-rsa.c,v 1.44 2010/07/16 14:07:35 djm Exp $ */
/*
* Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org>
*
@@ -30,6 +30,7 @@
#include "buffer.h"
#include "key.h"
#include "compat.h"
+#include "misc.h"
#include "ssh.h"
static int openssh_RSA_verify(int, u_char *, u_int, u_char *, u_int, RSA *);
@@ -46,9 +47,8 @@ ssh_rsa_sign(const Key *key, u_char **sigp, u_int *lenp,
int ok, nid;
Buffer b;
- if (key == NULL ||
- (key->type != KEY_RSA && key->type != KEY_RSA_CERT) ||
- key->rsa == NULL) {
+ if (key == NULL || key->rsa == NULL || (key->type != KEY_RSA &&
+ key->type != KEY_RSA_CERT && key->type != KEY_RSA_CERT_V00)) {
error("ssh_rsa_sign: no RSA key");
return -1;
}
@@ -115,9 +115,8 @@ ssh_rsa_verify(const Key *key, const u_char *signature, u_int signaturelen,
u_int len, dlen, modlen;
int rlen, ret, nid;
- if (key == NULL ||
- (key->type != KEY_RSA && key->type != KEY_RSA_CERT) ||
- key->rsa == NULL) {
+ if (key == NULL || key->rsa == NULL || (key->type != KEY_RSA &&
+ key->type != KEY_RSA_CERT && key->type != KEY_RSA_CERT_V00)) {
error("ssh_rsa_verify: no RSA key");
return -1;
}
@@ -212,7 +211,7 @@ openssh_RSA_verify(int type, u_char *hash, u_int hashlen,
u_char *sigbuf, u_int siglen, RSA *rsa)
{
u_int ret, rsasize, oidlen = 0, hlen = 0;
- int len;
+ int len, oidmatch, hashmatch;
const u_char *oid = NULL;
u_char *decrypted = NULL;
@@ -251,11 +250,13 @@ openssh_RSA_verify(int type, u_char *hash, u_int hashlen,
error("bad decrypted len: %d != %d + %d", len, hlen, oidlen);
goto done;
}
- if (memcmp(decrypted, oid, oidlen) != 0) {
+ oidmatch = timingsafe_bcmp(decrypted, oid, oidlen) == 0;
+ hashmatch = timingsafe_bcmp(decrypted + oidlen, hash, hlen) == 0;
+ if (!oidmatch) {
error("oid mismatch");
goto done;
}
- if (memcmp(decrypted + oidlen, hash, hlen) != 0) {
+ if (!hashmatch) {
error("hash mismatch");
goto done;
}
diff --git a/crypto/openssh/ssh.1 b/crypto/openssh/ssh.1
index 33cbc99..d5cd60c 100644
--- a/crypto/openssh/ssh.1
+++ b/crypto/openssh/ssh.1
@@ -34,9 +34,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: ssh.1,v 1.303 2010/03/26 00:26:58 djm Exp $
+.\" $OpenBSD: ssh.1,v 1.308 2010/08/04 05:37:01 djm Exp $
.\" $FreeBSD$
-.Dd March 26, 2010
+.Dd August 4 2010
.Dt SSH 1
.Os
.Sh NAME
@@ -44,46 +44,28 @@
.Nd OpenSSH SSH client (remote login program)
.Sh SYNOPSIS
.Nm ssh
+.Bk -words
.Op Fl 1246AaCfgKkMNnqsTtVvXxYy
.Op Fl b Ar bind_address
.Op Fl c Ar cipher_spec
-.Oo Fl D\ \&
-.Sm off
-.Oo Ar bind_address : Oc
-.Ar port
-.Sm on
-.Oc
+.Op Fl D Oo Ar bind_address : Oc Ns Ar port
.Op Fl e Ar escape_char
.Op Fl F Ar configfile
.Op Fl I Ar pkcs11
-.Bk -words
.Op Fl i Ar identity_file
-.Ek
-.Oo Fl L\ \&
-.Sm off
-.Oo Ar bind_address : Oc
-.Ar port : host : hostport
-.Sm on
-.Oc
-.Bk -words
+.Op Fl L Oo Ar bind_address : Oc Ns Ar port : Ns Ar host : Ns Ar hostport
.Op Fl l Ar login_name
-.Ek
.Op Fl m Ar mac_spec
.Op Fl O Ar ctl_cmd
.Op Fl o Ar option
.Op Fl p Ar port
-.Oo Fl R\ \&
-.Sm off
-.Oo Ar bind_address : Oc
-.Ar port : host : hostport
-.Sm on
-.Oc
+.Op Fl R Oo Ar bind_address : Oc Ns Ar port : Ns Ar host : Ns Ar hostport
.Op Fl S Ar ctl_path
.Op Fl W Ar host : Ns Ar port
-.Oo Fl w Ar local_tun Ns
-.Op : Ns Ar remote_tun Oc
+.Op Fl w Ar local_tun Ns Op : Ns Ar remote_tun
.Oo Ar user Ns @ Oc Ns Ar hostname
.Op Ar command
+.Ek
.Sh DESCRIPTION
.Nm
(SSH client) is a program for logging into a remote machine and for
@@ -195,7 +177,9 @@ is a comma-separated list of ciphers
listed in order of preference.
See the
.Cm Ciphers
-keyword for more information.
+keyword in
+.Xr ssh_config 5
+for more information.
.It Fl D Xo
.Sm off
.Oo Ar bind_address : Oc
@@ -219,14 +203,7 @@ will act as a SOCKS server.
Only root can forward privileged ports.
Dynamic port forwardings can also be specified in the configuration file.
.Pp
-IPv6 addresses can be specified with an alternative syntax:
-.Sm off
-.Xo
-.Op Ar bind_address No /
-.Ar port
-.Xc
-.Sm on
-or by enclosing the address in square brackets.
+IPv6 addresses can be specified by enclosing the address in square brackets.
Only the superuser can forward privileged ports.
By default, the local port is bound in accordance with the
.Cm GatewayPorts
@@ -337,15 +314,7 @@ port
.Ar hostport
from the remote machine.
Port forwardings can also be specified in the configuration file.
-IPv6 addresses can be specified with an alternative syntax:
-.Sm off
-.Xo
-.Op Ar bind_address No /
-.Ar port No / Ar host No /
-.Ar hostport
-.Xc
-.Sm on
-or by enclosing the address in square brackets.
+IPv6 addresses can be specified by enclosing the address in square brackets.
Only the superuser can forward privileged ports.
By default, the local port is bound in accordance with the
.Cm GatewayPorts
@@ -422,7 +391,9 @@ option is specified, the
argument is interpreted and passed to the master process.
Valid commands are:
.Dq check
-(check that the master process is running) and
+(check that the master process is running),
+.Dq forward
+(request forwardings without command execution) and
.Dq exit
(request the master to exit).
.It Fl o Ar option
@@ -527,15 +498,7 @@ from the local machine.
Port forwardings can also be specified in the configuration file.
Privileged ports can be forwarded only when
logging in as root on the remote machine.
-IPv6 addresses can be specified by enclosing the address in square braces or
-using an alternative syntax:
-.Sm off
-.Xo
-.Op Ar bind_address No /
-.Ar host No / Ar port No /
-.Ar hostport
-.Xc .
-.Sm on
+IPv6 addresses can be specified by enclosing the address in square braces.
.Pp
By default, the listening socket on the server will be bound to the loopback
interface only.
@@ -559,8 +522,11 @@ argument is
.Ql 0 ,
the listen port will be dynamically allocated on the server and reported
to the client at run time.
+When used together with
+.Ic -O forward
+the allocated port will be printed to the standard output.
.It Fl S Ar ctl_path
-Specifies the location of a control socket for connection sharing
+Specifies the location of a control socket for connection sharing,
or the string
.Dq none
to disable connection sharing.
diff --git a/crypto/openssh/ssh.c b/crypto/openssh/ssh.c
index 884d7e9..11eac21 100644
--- a/crypto/openssh/ssh.c
+++ b/crypto/openssh/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.335 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.346 2010/08/12 21:49:44 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -80,6 +80,7 @@ __RCSID("$FreeBSD$");
#include "ssh.h"
#include "ssh1.h"
#include "ssh2.h"
+#include "canohost.h"
#include "compat.h"
#include "cipher.h"
#include "packet.h"
@@ -128,6 +129,15 @@ int no_shell_flag = 0;
int stdin_null_flag = 0;
/*
+ * Flag indicating that the current process should be backgrounded and
+ * a new slave launched in the foreground for ControlPersist.
+ */
+int need_controlpersist_detach = 0;
+
+/* Copies of flags for ControlPersist foreground slave */
+int ostdin_null_flag, ono_shell_flag, ono_tty_flag, otty_flag;
+
+/*
* Flag indicating that ssh should fork after authentication. This is useful
* so that the passphrase can be entered manually, and then ssh goes to the
* background.
@@ -229,6 +239,12 @@ main(int ac, char **av)
init_rng();
/*
+ * Discard other fds that are hanging around. These can cause problem
+ * with backgrounded ssh processes started by ControlPersist.
+ */
+ closefrom(STDERR_FILENO + 1);
+
+ /*
* Save the original real uid. It will be needed later (uid-swapping
* may clobber the real uid).
*/
@@ -328,6 +344,8 @@ main(int ac, char **av)
fatal("Multiplexing command already specified");
if (strcmp(optarg, "check") == 0)
muxclient_command = SSHMUX_COMMAND_ALIVE_CHECK;
+ else if (strcmp(optarg, "forward") == 0)
+ muxclient_command = SSHMUX_COMMAND_FORWARD;
else if (strcmp(optarg, "exit") == 0)
muxclient_command = SSHMUX_COMMAND_TERMINATE;
else
@@ -621,7 +639,7 @@ main(int ac, char **av)
tty_flag = 1;
/* Force no tty */
- if (no_tty_flag)
+ if (no_tty_flag || muxclient_command != 0)
tty_flag = 0;
/* Do not allocate a tty if stdin is not a tty. */
if ((!isatty(fileno(stdin)) || stdin_null_flag) && !force_tty_flag) {
@@ -677,6 +695,11 @@ main(int ac, char **av)
options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
}
+ if (options.hostname != NULL) {
+ host = percent_expand(options.hostname,
+ "h", host, (char *)NULL);
+ }
+
if (options.local_command != NULL) {
char thishost[NI_MAXHOST];
@@ -686,16 +709,12 @@ main(int ac, char **av)
debug3("expanding LocalCommand: %s", options.local_command);
cp = options.local_command;
options.local_command = percent_expand(cp, "d", pw->pw_dir,
- "h", options.hostname? options.hostname : host,
- "l", thishost, "n", host, "r", options.user, "p", buf,
- "u", pw->pw_name, (char *)NULL);
+ "h", host, "l", thishost, "n", host, "r", options.user,
+ "p", buf, "u", pw->pw_name, (char *)NULL);
debug3("expanded LocalCommand: %s", options.local_command);
xfree(cp);
}
- if (options.hostname != NULL)
- host = options.hostname;
-
/* Find canonic host name. */
if (strchr(host, '.') == 0) {
struct addrinfo hints;
@@ -779,26 +798,34 @@ main(int ac, char **av)
sensitive_data.external_keysign = 0;
if (options.rhosts_rsa_authentication ||
options.hostbased_authentication) {
- sensitive_data.nkeys = 3;
+ sensitive_data.nkeys = 5;
sensitive_data.keys = xcalloc(sensitive_data.nkeys,
sizeof(Key));
PRIV_START;
sensitive_data.keys[0] = key_load_private_type(KEY_RSA1,
_PATH_HOST_KEY_FILE, "", NULL, NULL);
- sensitive_data.keys[1] = key_load_private_type(KEY_DSA,
+ sensitive_data.keys[1] = key_load_private_cert(KEY_DSA,
+ _PATH_HOST_DSA_KEY_FILE, "", NULL);
+ sensitive_data.keys[2] = key_load_private_cert(KEY_RSA,
+ _PATH_HOST_RSA_KEY_FILE, "", NULL);
+ sensitive_data.keys[3] = key_load_private_type(KEY_DSA,
_PATH_HOST_DSA_KEY_FILE, "", NULL, NULL);
- sensitive_data.keys[2] = key_load_private_type(KEY_RSA,
+ sensitive_data.keys[4] = key_load_private_type(KEY_RSA,
_PATH_HOST_RSA_KEY_FILE, "", NULL, NULL);
PRIV_END;
if (options.hostbased_authentication == 1 &&
sensitive_data.keys[0] == NULL &&
- sensitive_data.keys[1] == NULL &&
- sensitive_data.keys[2] == NULL) {
- sensitive_data.keys[1] = key_load_public(
+ sensitive_data.keys[3] == NULL &&
+ sensitive_data.keys[4] == NULL) {
+ sensitive_data.keys[1] = key_load_cert(
+ _PATH_HOST_DSA_KEY_FILE);
+ sensitive_data.keys[2] = key_load_cert(
+ _PATH_HOST_RSA_KEY_FILE);
+ sensitive_data.keys[3] = key_load_public(
_PATH_HOST_DSA_KEY_FILE, NULL);
- sensitive_data.keys[2] = key_load_public(
+ sensitive_data.keys[4] = key_load_public(
_PATH_HOST_RSA_KEY_FILE, NULL);
sensitive_data.external_keysign = 1;
}
@@ -845,6 +872,13 @@ main(int ac, char **av)
ssh_login(&sensitive_data, host, (struct sockaddr *)&hostaddr,
pw, timeout_ms);
+ if (packet_connection_is_on_socket()) {
+ verbose("Authenticated to %s ([%s]:%d).", host,
+ get_remote_ipaddr(), get_remote_port());
+ } else {
+ verbose("Authenticated to %s (via proxy).", host);
+ }
+
/* We no longer need the private host keys. Clear them now. */
if (sensitive_data.nkeys != 0) {
for (i = 0; i < sensitive_data.nkeys; i++) {
@@ -884,6 +918,61 @@ main(int ac, char **av)
return exit_status;
}
+static void
+control_persist_detach(void)
+{
+ pid_t pid;
+ int devnull;
+
+ debug("%s: backgrounding master process", __func__);
+
+ /*
+ * master (current process) into the background, and make the
+ * foreground process a client of the backgrounded master.
+ */
+ switch ((pid = fork())) {
+ case -1:
+ fatal("%s: fork: %s", __func__, strerror(errno));
+ case 0:
+ /* Child: master process continues mainloop */
+ break;
+ default:
+ /* Parent: set up mux slave to connect to backgrounded master */
+ debug2("%s: background process is %ld", __func__, (long)pid);
+ stdin_null_flag = ostdin_null_flag;
+ no_shell_flag = ono_shell_flag;
+ no_tty_flag = ono_tty_flag;
+ tty_flag = otty_flag;
+ close(muxserver_sock);
+ muxserver_sock = -1;
+ muxclient(options.control_path);
+ /* muxclient() doesn't return on success. */
+ fatal("Failed to connect to new control master");
+ }
+ if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) {
+ error("%s: open(\"/dev/null\"): %s", __func__,
+ strerror(errno));
+ } else {
+ if (dup2(devnull, STDIN_FILENO) == -1 ||
+ dup2(devnull, STDOUT_FILENO) == -1)
+ error("%s: dup2: %s", __func__, strerror(errno));
+ if (devnull > STDERR_FILENO)
+ close(devnull);
+ }
+}
+
+/* Do fork() after authentication. Used by "ssh -f" */
+static void
+fork_postauth(void)
+{
+ if (need_controlpersist_detach)
+ control_persist_detach();
+ debug("forking to background");
+ fork_after_authentication_flag = 0;
+ if (daemon(1, 1) < 0)
+ fatal("daemon() failed: %.200s", strerror(errno));
+}
+
/* Callback for remote forward global requests */
static void
ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
@@ -895,9 +984,10 @@ ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure",
rfwd->listen_port, rfwd->connect_host, rfwd->connect_port);
if (type == SSH2_MSG_REQUEST_SUCCESS && rfwd->listen_port == 0) {
+ rfwd->allocated_port = packet_get_int();
logit("Allocated port %u for remote forward to %s:%d",
- packet_get_int(),
- rfwd->connect_host, rfwd->connect_port);
+ rfwd->allocated_port,
+ rfwd->connect_host, rfwd->connect_port);
}
if (type == SSH2_MSG_REQUEST_FAILURE) {
@@ -910,12 +1000,8 @@ ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt)
}
if (++remote_forward_confirms_received == options.num_remote_forwards) {
debug("All remote forwarding requests processed");
- if (fork_after_authentication_flag) {
- fork_after_authentication_flag = 0;
- if (daemon(1, 1) < 0)
- fatal("daemon() failed: %.200s",
- strerror(errno));
- }
+ if (fork_after_authentication_flag)
+ fork_postauth();
}
}
@@ -1111,7 +1197,9 @@ ssh_session(void)
char *proto, *data;
/* Get reasonable local authentication information. */
client_x11_get_proto(display, options.xauth_location,
- options.forward_x11_trusted, &proto, &data);
+ options.forward_x11_trusted,
+ options.forward_x11_timeout,
+ &proto, &data);
/* Request forwarding with authentication spoofing. */
debug("Requesting X11 forwarding with authentication "
"spoofing.");
@@ -1157,12 +1245,13 @@ ssh_session(void)
* If requested and we are not interested in replies to remote
* forwarding requests, then let ssh continue in the background.
*/
- if (fork_after_authentication_flag &&
- (!options.exit_on_forward_failure ||
- options.num_remote_forwards == 0)) {
- fork_after_authentication_flag = 0;
- if (daemon(1, 1) < 0)
- fatal("daemon() failed: %.200s", strerror(errno));
+ if (fork_after_authentication_flag) {
+ if (options.exit_on_forward_failure &&
+ options.num_remote_forwards > 0) {
+ debug("deferring postauth fork until remote forward "
+ "confirmation received");
+ } else
+ fork_postauth();
}
/*
@@ -1193,18 +1282,22 @@ ssh_session(void)
/* request pty/x11/agent/tcpfwd/shell for channel */
static void
-ssh_session2_setup(int id, void *arg)
+ssh_session2_setup(int id, int success, void *arg)
{
extern char **environ;
const char *display;
int interactive = tty_flag;
+ if (!success)
+ return; /* No need for error message, channels code sens one */
+
display = getenv("DISPLAY");
if (options.forward_x11 && display != NULL) {
char *proto, *data;
/* Get reasonable local authentication information. */
client_x11_get_proto(display, options.xauth_location,
- options.forward_x11_trusted, &proto, &data);
+ options.forward_x11_trusted,
+ options.forward_x11_timeout, &proto, &data);
/* Request forwarding with authentication spoofing. */
debug("Requesting X11 forwarding with authentication "
"spoofing.");
@@ -1281,6 +1374,31 @@ ssh_session2(void)
/* XXX should be pre-session */
ssh_init_forwarding();
+ /* Start listening for multiplex clients */
+ muxserver_listen();
+
+ /*
+ * If we are in control persist mode, then prepare to background
+ * ourselves and have a foreground client attach as a control
+ * slave. NB. we must save copies of the flags that we override for
+ * the backgrounding, since we defer attachment of the slave until
+ * after the connection is fully established (in particular,
+ * async rfwd replies have been received for ExitOnForwardFailure).
+ */
+ if (options.control_persist && muxserver_sock != -1) {
+ ostdin_null_flag = stdin_null_flag;
+ ono_shell_flag = no_shell_flag;
+ ono_tty_flag = no_tty_flag;
+ otty_flag = tty_flag;
+ stdin_null_flag = 1;
+ no_shell_flag = 1;
+ no_tty_flag = 1;
+ tty_flag = 0;
+ if (!fork_after_authentication_flag)
+ need_controlpersist_detach = 1;
+ fork_after_authentication_flag = 1;
+ }
+
if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN))
id = ssh_session2_open();
@@ -1299,14 +1417,17 @@ ssh_session2(void)
options.permit_local_command)
ssh_local_cmd(options.local_command);
- /* Start listening for multiplex clients */
- muxserver_listen();
-
- /* If requested, let ssh continue in the background. */
+ /*
+ * If requested and we are not interested in replies to remote
+ * forwarding requests, then let ssh continue in the background.
+ */
if (fork_after_authentication_flag) {
- fork_after_authentication_flag = 0;
- if (daemon(1, 1) < 0)
- fatal("daemon() failed: %.200s", strerror(errno));
+ if (options.exit_on_forward_failure &&
+ options.num_remote_forwards > 0) {
+ debug("deferring postauth fork until remote forward "
+ "confirmation received");
+ } else
+ fork_postauth();
}
if (options.use_roaming)
diff --git a/crypto/openssh/ssh.h b/crypto/openssh/ssh.h
index 186cfff..c94633b 100644
--- a/crypto/openssh/ssh.h
+++ b/crypto/openssh/ssh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.h,v 1.78 2006/08/03 03:34:42 deraadt Exp $ */
+/* $OpenBSD: ssh.h,v 1.79 2010/06/25 07:14:46 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -18,9 +18,6 @@
/* Default port number. */
#define SSH_DEFAULT_PORT 22
-/* Maximum number of TCP/IP ports forwarded per direction. */
-#define SSH_MAX_FORWARDS_PER_DIRECTION 100
-
/*
* Maximum number of RSA authentication identity files that can be specified
* in configuration files or on the command line.
diff --git a/crypto/openssh/ssh_config b/crypto/openssh/ssh_config
index 3bda1b9..e0c7f69 100644
--- a/crypto/openssh/ssh_config
+++ b/crypto/openssh/ssh_config
@@ -46,4 +46,4 @@
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
-# VersionAddendum FreeBSD-20100428
+# VersionAddendum FreeBSD-20101111
diff --git a/crypto/openssh/ssh_config.5 b/crypto/openssh/ssh_config.5
index ec6cd56..e36e574 100644
--- a/crypto/openssh/ssh_config.5
+++ b/crypto/openssh/ssh_config.5
@@ -34,9 +34,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: ssh_config.5,v 1.130 2010/03/26 01:06:13 dtucker Exp $
+.\" $OpenBSD: ssh_config.5,v 1.138 2010/08/04 05:37:01 djm Exp $
.\" $FreeBSD$
-.Dd March 26, 2010
+.Dd August 4, 2010
.Dt SSH_CONFIG 5
.Os
.Sh NAME
@@ -320,6 +320,28 @@ It is recommended that any
used for opportunistic connection sharing include
at least %h, %p, and %r.
This ensures that shared connections are uniquely identified.
+.It Cm ControlPersist
+When used in conjunction with
+.Cm ControlMaster ,
+specifies that the master connection should remain open
+in the background (waiting for future client connections)
+after the initial client connection has been closed.
+If set to
+.Dq no ,
+then the master connection will not be placed into the background,
+and will close as soon as the initial client connection is closed.
+If set to
+.Dq yes ,
+then the master connection will remain in the background indefinitely
+(until killed or closed via a mechanism such as the
+.Xr ssh 1
+.Dq Fl O No exit
+option).
+If set to a time in seconds, or a time in any of the formats documented in
+.Xr sshd_config 5 ,
+then the backgrounded master connection will automatically terminate
+after it has remained idle (with no client connections) for the
+specified time.
.It Cm DynamicForward
Specifies that a TCP port on the local machine be forwarded
over the secure channel, and the application
@@ -330,9 +352,7 @@ The argument must be
.Sm off
.Oo Ar bind_address : Oc Ar port .
.Sm on
-IPv6 addresses can be specified by enclosing addresses in square brackets or
-by using an alternative syntax:
-.Oo Ar bind_address Ns / Oc Ns Ar port .
+IPv6 addresses can be specified by enclosing addresses in square brackets.
By default, the local port is bound in accordance with the
.Cm GatewayPorts
setting.
@@ -433,6 +453,17 @@ An attacker may then be able to perform activities such as keystroke monitoring
if the
.Cm ForwardX11Trusted
option is also enabled.
+.It Cm ForwardX11Timeout
+Specify a timeout for untrusted X11 forwarding
+using the format described in the
+.Sx TIME FORMATS
+section of
+.Xr sshd_config 5 .
+X11 connections received by
+.Xr ssh 1
+after this time will be refused.
+The default is to disable untrusted X11 forwarding after twenty minutes has
+elapsed.
.It Cm ForwardX11Trusted
If this option is set to
.Dq yes ,
@@ -527,6 +558,10 @@ or for multiple servers running on a single host.
.It Cm HostName
Specifies the real host name to log into.
This can be used to specify nicknames or abbreviations for hosts.
+If the hostname contains the character sequence
+.Ql %h ,
+then this will be replaced with the host name specified on the commandline
+(this is useful for manipulating unqualified names).
The default is the name given on the command line.
Numeric IP addresses are also permitted (both on the command line and in
.Cm HostName
@@ -642,11 +677,7 @@ The first argument must be
.Sm on
and the second argument must be
.Ar host : Ns Ar hostport .
-IPv6 addresses can be specified by enclosing addresses in square brackets or
-by using an alternative syntax:
-.Oo Ar bind_address Ns / Oc Ns Ar port
-and
-.Ar host Ns / Ns Ar hostport .
+IPv6 addresses can be specified by enclosing addresses in square brackets.
Multiple forwardings may be specified, and additional forwardings can be
given on the command line.
Only the superuser can forward privileged ports.
@@ -733,10 +764,12 @@ authentication methods.
This allows a client to prefer one method (e.g.\&
.Cm keyboard-interactive )
over another method (e.g.\&
-.Cm password )
-The default for this option is:
-.Do gssapi-with-mic,hostbased,publickey,keyboard-interactive,password
-.Dc .
+.Cm password ) .
+The default is:
+.Bd -literal -offset indent
+gssapi-with-mic,hostbased,publickey,
+keyboard-interactive,password
+.Ed
.It Cm Protocol
Specifies the protocol versions
.Xr ssh 1
@@ -758,12 +791,14 @@ Specifies the command to use to connect to the server.
The command
string extends to the end of the line, and is executed with
the user's shell.
-In the command string,
+In the command string, any occurrence of
.Ql %h
will be substituted by the host name to
-connect and
+connect,
.Ql %p
-by the port.
+by the port, and
+.Ql %r
+by the remote user name.
The command can be basically anything,
and should read from its standard input and write to its standard output.
It should eventually connect an
@@ -822,11 +857,7 @@ The first argument must be
.Sm on
and the second argument must be
.Ar host : Ns Ar hostport .
-IPv6 addresses can be specified by enclosing addresses in square brackets
-or by using an alternative syntax:
-.Oo Ar bind_address Ns / Oc Ns Ar port
-and
-.Ar host Ns / Ns Ar hostport .
+IPv6 addresses can be specified by enclosing addresses in square brackets.
Multiple forwardings may be specified, and additional
forwardings can be given on the command line.
Privileged ports can be forwarded only when
@@ -1083,7 +1114,7 @@ in
Specifies a string to append to the regular version string to identify
OS- or site-specific modifications.
The default is
-.Dq FreeBSD-20100428 .
+.Dq FreeBSD-20101111 .
.It Cm VisualHostKey
If this flag is set to
.Dq yes ,
diff --git a/crypto/openssh/sshconnect.c b/crypto/openssh/sshconnect.c
index a54d942..f84d5bb 100644
--- a/crypto/openssh/sshconnect.c
+++ b/crypto/openssh/sshconnect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect.c,v 1.220 2010/03/04 10:36:03 djm Exp $ */
+/* $OpenBSD: sshconnect.c,v 1.224 2010/04/16 21:14:27 djm Exp $ */
/* $FreeBSD$ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -102,8 +102,8 @@ ssh_proxy_connect(const char *host, u_short port, const char *proxy_command)
* (e.g. Solaris)
*/
xasprintf(&tmp, "exec %s", proxy_command);
- command_string = percent_expand(tmp, "h", host,
- "p", strport, (char *)NULL);
+ command_string = percent_expand(tmp, "h", host, "p", strport,
+ "r", options.user, (char *)NULL);
xfree(tmp);
/* Create pipes for communicating with the proxy. */
@@ -587,9 +587,9 @@ check_host_cert(const char *host, const Key *host_key)
error("%s", reason);
return 0;
}
- if (buffer_len(&host_key->cert->constraints) != 0) {
- error("Certificate for %s contains unsupported constraint(s)",
- host);
+ if (buffer_len(&host_key->cert->critical) != 0) {
+ error("Certificate for %s contains unsupported "
+ "critical options(s)", host);
return 0;
}
return 1;
@@ -740,7 +740,7 @@ check_host_key(char *hostname, struct sockaddr *hostaddr, u_short port,
debug("Host '%.200s' is known and matches the %s host %s.",
host, type, want_cert ? "certificate" : "key");
debug("Found %s in %s:%d",
- want_cert ? "certificate" : "key", host_file, host_line);
+ want_cert ? "CA key" : "key", host_file, host_line);
if (want_cert && !check_host_cert(hostname, host_key))
goto fail;
if (options.check_host_ip && ip_status == HOST_NEW) {
diff --git a/crypto/openssh/sshconnect2.c b/crypto/openssh/sshconnect2.c
index 2a5943e..4c379ae 100644
--- a/crypto/openssh/sshconnect2.c
+++ b/crypto/openssh/sshconnect2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect2.c,v 1.180 2010/02/26 20:29:54 djm Exp $ */
+/* $OpenBSD: sshconnect2.c,v 1.183 2010/04/26 22:28:24 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -195,7 +195,7 @@ struct Authctxt {
const char *host;
const char *service;
Authmethod *method;
- int success;
+ sig_atomic_t success;
char *authlist;
/* pubkey */
Idlist keys;
@@ -1140,8 +1140,11 @@ sign_and_send_pubkey(Authctxt *authctxt, Identity *id)
u_int skip = 0;
int ret = -1;
int have_sig = 1;
+ char *fp;
- debug3("sign_and_send_pubkey");
+ fp = key_fingerprint(id->key, SSH_FP_MD5, SSH_FP_HEX);
+ debug3("sign_and_send_pubkey: %s %s", key_type(id->key), fp);
+ xfree(fp);
if (key_to_blob(id->key, &blob, &bloblen) == 0) {
/* we cannot handle this key */
@@ -1398,7 +1401,8 @@ userauth_pubkey(Authctxt *authctxt)
* private key instead
*/
if (id->key && id->key->type != KEY_RSA1) {
- debug("Offering public key: %s", id->filename);
+ debug("Offering %s public key: %s", key_type(id->key),
+ id->filename);
sent = send_pubkey_test(authctxt, id);
} else if (id->key == NULL) {
debug("Trying private key: %s", id->filename);
diff --git a/crypto/openssh/sshd.8 b/crypto/openssh/sshd.8
index 96bb26e..17909b8 100644
--- a/crypto/openssh/sshd.8
+++ b/crypto/openssh/sshd.8
@@ -34,9 +34,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: sshd.8,v 1.255 2010/03/05 06:50:35 jmc Exp $
+.\" $OpenBSD: sshd.8,v 1.257 2010/08/04 05:37:01 djm Exp $
.\" $FreeBSD$
-.Dd March 5, 2010
+.Dd August 4, 2010
.Dt SSHD 8
.Os
.Sh NAME
@@ -598,13 +598,23 @@ Limit local
.Li ``ssh -L''
port forwarding such that it may only connect to the specified host and
port.
-IPv6 addresses can be specified with an alternative syntax:
-.Ar host Ns / Ns Ar port .
+IPv6 addresses can be specified by enclosing the address in square brackets.
Multiple
.Cm permitopen
options may be applied separated by commas.
No pattern matching is performed on the specified hostnames,
they must be literal domains or addresses.
+.It Cm principals="principals"
+On a
+.Cm cert-authority
+line, specifies allowed principals for certificate authentication as a
+comma-separated list.
+At least one name from the list must appear in the certificate's
+list of principals for the certificate to be accepted.
+This option is ignored for keys that are not marked as trusted certificate
+signers using the
+.Cm cert-authority
+option.
.It Cm tunnel="n"
Force a
.Xr tun 4
diff --git a/crypto/openssh/sshd.c b/crypto/openssh/sshd.c
index 5bd7cd4..d3f5bb8 100644
--- a/crypto/openssh/sshd.c
+++ b/crypto/openssh/sshd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshd.c,v 1.374 2010/03/07 11:57:13 dtucker Exp $ */
+/* $OpenBSD: sshd.c,v 1.375 2010/04/16 01:47:26 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -755,6 +755,8 @@ list_hostkey_types(void)
if (key == NULL)
continue;
switch (key->type) {
+ case KEY_RSA_CERT_V00:
+ case KEY_DSA_CERT_V00:
case KEY_RSA_CERT:
case KEY_DSA_CERT:
if (buffer_len(&b) > 0)
@@ -778,10 +780,17 @@ get_hostkey_by_type(int type, int need_private)
Key *key;
for (i = 0; i < options.num_host_key_files; i++) {
- if (type == KEY_RSA_CERT || type == KEY_DSA_CERT)
+ switch (type) {
+ case KEY_RSA_CERT_V00:
+ case KEY_DSA_CERT_V00:
+ case KEY_RSA_CERT:
+ case KEY_DSA_CERT:
key = sensitive_data.host_certificates[i];
- else
+ break;
+ default:
key = sensitive_data.host_keys[i];
+ break;
+ }
if (key != NULL && key->type == type)
return need_private ?
sensitive_data.host_keys[i] : key;
diff --git a/crypto/openssh/sshd_config b/crypto/openssh/sshd_config
index 3c700f0..bb8d24bc 100644
--- a/crypto/openssh/sshd_config
+++ b/crypto/openssh/sshd_config
@@ -14,7 +14,7 @@
# Note that some of FreeBSD's defaults differ from OpenBSD's, and
# FreeBSD has a few additional options.
-#VersionAddendum FreeBSD-20100428
+#VersionAddendum FreeBSD-20101111
#Port 22
#AddressFamily any
diff --git a/crypto/openssh/sshd_config.5 b/crypto/openssh/sshd_config.5
index 4e918c4..cea5297 100644
--- a/crypto/openssh/sshd_config.5
+++ b/crypto/openssh/sshd_config.5
@@ -34,9 +34,9 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: sshd_config.5,v 1.120 2010/03/04 23:17:25 djm Exp $
+.\" $OpenBSD: sshd_config.5,v 1.125 2010/06/30 07:28:34 jmc Exp $
.\" $FreeBSD$
-.Dd March 4, 2010
+.Dd June 30, 2010
.Dt SSHD_CONFIG 5
.Os
.Sh NAME
@@ -156,6 +156,10 @@ for more information on patterns.
.It Cm AuthorizedKeysFile
Specifies the file that contains the public keys that can be used
for user authentication.
+The format is described in the
+.Sx AUTHORIZED_KEYS FILE FORMAT
+section of
+.Xr sshd 8 .
.Cm AuthorizedKeysFile
may contain tokens of the form %T which are substituted during connection
setup.
@@ -168,6 +172,47 @@ is taken to be an absolute path or one relative to the user's home
directory.
The default is
.Dq .ssh/authorized_keys .
+.It Cm AuthorizedPrincipalsFile
+Specifies a file that lists principal names that are accepted for
+certificate authentication.
+When using certificates signed by a key listed in
+.Cm TrustedUserCAKeys ,
+this file lists names, one of which must appear in the certificate for it
+to be accepted for authentication.
+Names are listed one per line preceded by key options (as described
+in
+.Sx AUTHORIZED_KEYS FILE FORMAT
+in
+.Xr sshd 8 ) .
+Empty lines and comments starting with
+.Ql #
+are ignored.
+.Pp
+.Cm AuthorizedPrincipalsFile
+may contain tokens of the form %T which are substituted during connection
+setup.
+The following tokens are defined: %% is replaced by a literal '%',
+%h is replaced by the home directory of the user being authenticated, and
+%u is replaced by the username of that user.
+After expansion,
+.Cm AuthorizedPrincipalsFile
+is taken to be an absolute path or one relative to the user's home
+directory.
+.Pp
+The default is not to use a principals file \(en in this case, the username
+of the user must appear in a certificate's principals list for it to be
+accepted.
+Note that
+.Cm AuthorizedPrincipalsFile
+is only used when authentication proceeds using a CA listed in
+.Cm TrustedUserCAKeys
+and is not consulted for certification authorities trusted via
+.Pa ~/.ssh/authorized_keys ,
+though the
+.Cm principals=
+key option offers a similar facility (see
+.Xr sshd 8
+for details).
.It Cm Banner
The contents of the specified file are sent to the remote user before
authentication is allowed.
@@ -609,12 +654,15 @@ keyword.
Available keywords are
.Cm AllowAgentForwarding ,
.Cm AllowTcpForwarding ,
+.Cm AuthorizedKeysFile ,
+.Cm AuthorizedPrincipalsFile ,
.Cm Banner ,
.Cm ChrootDirectory ,
.Cm ForceCommand ,
.Cm GatewayPorts ,
.Cm GSSAPIAuthentication ,
.Cm HostbasedAuthentication ,
+.Cm HostbasedUsesNameFromPacketOnly ,
.Cm KbdInteractiveAuthentication ,
.Cm KerberosAuthentication ,
.Cm MaxAuthTries ,
@@ -623,6 +671,7 @@ Available keywords are
.Cm PermitEmptyPasswords ,
.Cm PermitOpen ,
.Cm PermitRootLogin ,
+.Cm PermitTunnel ,
.Cm PubkeyAuthentication ,
.Cm RhostsRSAAuthentication ,
.Cm RSAAuthentication ,
@@ -988,7 +1037,7 @@ The default is
Specifies a string to append to the regular version string to identify
OS- or site-specific modifications.
The default is
-.Dq FreeBSD-20100428 .
+.Dq FreeBSD-20101111 .
.It Cm X11DisplayOffset
Specifies the first display number available for
.Xr sshd 8 Ns 's
diff --git a/crypto/openssh/version.h b/crypto/openssh/version.h
index 6cc8d84..20aeb01 100644
--- a/crypto/openssh/version.h
+++ b/crypto/openssh/version.h
@@ -1,12 +1,12 @@
-/* $OpenBSD: version.h,v 1.58 2010/03/16 16:36:49 djm Exp $ */
+/* $OpenBSD: version.h,v 1.59 2010/08/08 16:26:42 djm Exp $ */
/* $FreeBSD$ */
#ifndef SSH_VERSION
#define SSH_VERSION (ssh_version_get())
#define SSH_RELEASE (ssh_version_get())
-#define SSH_VERSION_BASE "OpenSSH_5.5p1"
-#define SSH_VERSION_ADDENDUM "FreeBSD-20100428"
+#define SSH_VERSION_BASE "OpenSSH_5.6p1"
+#define SSH_VERSION_ADDENDUM "FreeBSD-20101111"
const char *ssh_version_get(void);
void ssh_version_set_addendum(const char *);
diff --git a/etc/periodic/security/Makefile b/etc/periodic/security/Makefile
index 02f8b76..fc67723 100644
--- a/etc/periodic/security/Makefile
+++ b/etc/periodic/security/Makefile
@@ -7,7 +7,6 @@ FILES= 100.chksetuid \
300.chkuid0 \
400.passwdless \
410.logincheck \
- 460.chkportsum \
700.kernelmsg \
800.loginfail \
900.tcpwrap \
@@ -28,4 +27,8 @@ FILES+= 500.ipfwdenied \
FILES+= 520.pfdenied
.endif
+.if ${MK_PKGTOOLS} != "no"
+FILES+= 460.chkportsum
+.endif
+
.include <bsd.prog.mk>
diff --git a/gnu/lib/libgcc/Makefile b/gnu/lib/libgcc/Makefile
index b3480dc..2021c8c 100644
--- a/gnu/lib/libgcc/Makefile
+++ b/gnu/lib/libgcc/Makefile
@@ -3,7 +3,6 @@
GCCDIR= ${.CURDIR}/../../../contrib/gcc
GCCLIB= ${.CURDIR}/../../../contrib/gcclibs
-LIB= gcc
SHLIB_NAME= libgcc_s.so.1
SHLIBDIR?= /lib
@@ -27,7 +26,7 @@ CFLAGS+= -DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
LDFLAGS+= -nodefaultlibs
LDADD+= -lc
-OBJS= # added to below in various ways depending on TARGET_ARCH
+OBJS= # added to below in various ways depending on TARGET_CPUARCH
#---------------------------------------------------------------------------
#
@@ -100,7 +99,7 @@ LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _udivdi3 _umoddi3 _udiv_w_sdiv _udivmoddi4
# Platform specific bits.
# When upgrading GCC, get the following definitions from config/<cpu>/t-*
#
-.if ${TARGET_ARCH} == "arm"
+.if ${TARGET_CPUARCH} == "arm"
# from config/arm/t-strongarm-elf
CFLAGS+= -Dinhibit_libc -fno-inline
LIB1ASMSRC = lib1funcs.asm
@@ -116,7 +115,7 @@ LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
# _fixsfsi _fixunssfsi _floatdidf _floatdisf
.endif
-.if ${TARGET_ARCH} == "mips"
+.if ${TARGET_CPUARCH} == "mips"
LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
.if defined(TARGET_ABI) && ${TARGET_ABI} != "o32"
LIB2FUNCS_EXTRA+= floatdidf.c fixunsdfsi.c
@@ -126,7 +125,7 @@ LIB2FUNCS_EXTRA+= fixdfdi.c fixunssfsi.c
.endif
.endif
-.if ${TARGET_ARCH} == "ia64"
+.if ${TARGET_CPUARCH} == "ia64"
# from config/ia64/t-ia64
LIB1ASMSRC = lib1funcs.asm
LIB1ASMFUNCS = __divxf3 __divdf3 __divsf3 \
@@ -137,18 +136,18 @@ LIB1ASMFUNCS = __divxf3 __divdf3 __divsf3 \
LIB2ADDEH = unwind-ia64.c unwind-sjlj.c unwind-c.c
.endif
-.if ${TARGET_ARCH} == "powerpc"
+.if ${TARGET_CPUARCH} == "powerpc"
# from config/rs6000/t-ppccomm
LIB2FUNCS_EXTRA = tramp.asm
LIB2FUNCS_STATIC_EXTRA = eabi.asm
.endif
-.if ${TARGET_ARCH} == "powerpc64"
+.if ${TARGET_CPUARCH} == "powerpc64"
# from config/rs6000/t-ppccomm
LIB2FUNCS_EXTRA = tramp.asm
.endif
-.if ${TARGET_ARCH} == "sparc64"
+.if ${TARGET_CPUARCH} == "sparc64"
# from config/sparc/t-elf
LIB1ASMSRC = lb1spc.asm
LIB1ASMFUNCS = _mulsi3 _divsi3 _modsi3
@@ -195,8 +194,8 @@ OBJ_GRPS = STD DIV
#
# Floating point emulation functions
#
-.if ${TARGET_ARCH} == "armNOT_YET" || \
- ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "sparc64"
+.if ${TARGET_CPUARCH} == "armNOT_YET" || \
+ ${TARGET_CPUARCH} == "powerpc" || ${TARGET_CPUARCH} == "sparc64"
FPBIT_CFLAGS = -DFINE_GRAINED_LIBRARIES -DFLOAT
DPBIT_CFLAGS = -DFINE_GRAINED_LIBRARIES
@@ -334,21 +333,21 @@ CLEANFILES += libgcc.map
#
# Build additional static libgcc_eh[_p].a libraries.
#
-lib${LIB}_eh.a: ${EH_OBJS_T}
- @${ECHO} building static ${LIB}_eh library
+libgcc_eh.a: ${EH_OBJS_T}
+ @${ECHO} building static gcc_eh library
@rm -f ${.TARGET}
@${AR} cq ${.TARGET} `lorder ${EH_OBJS_T} | tsort -q`
${RANLIB} ${.TARGET}
-all: lib${LIB}_eh.a
+all: libgcc_eh.a
.if ${MK_PROFILE} != "no"
-lib${LIB}_eh_p.a: ${EH_OBJS_P}
- @${ECHO} building profiled ${LIB}_eh library
+libgcc_eh_p.a: ${EH_OBJS_P}
+ @${ECHO} building profiled gcc_eh library
@rm -f ${.TARGET}
@${AR} cq ${.TARGET} `lorder ${EH_OBJS_P} | tsort -q`
${RANLIB} ${.TARGET}
-all: lib${LIB}_eh_p.a
+all: libgcc_eh_p.a
.endif
_libinstall: _lib-eh-install
@@ -356,14 +355,14 @@ _libinstall: _lib-eh-install
_lib-eh-install:
.if ${MK_INSTALLLIB} != "no"
${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
- ${_INSTALLFLAGS} lib${LIB}_eh.a ${DESTDIR}${LIBDIR}
+ ${_INSTALLFLAGS} libgcc_eh.a ${DESTDIR}${LIBDIR}
.endif
.if ${MK_PROFILE} != "no"
${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
- ${_INSTALLFLAGS} lib${LIB}_eh_p.a ${DESTDIR}${LIBDIR}
+ ${_INSTALLFLAGS} libgcc_eh_p.a ${DESTDIR}${LIBDIR}
.endif
-CLEANFILES+= lib${LIB}_eh.a lib${LIB}_eh_p.a ${EH_OBJS_T} ${EH_OBJS_P}
+CLEANFILES+= libgcc_eh.a libgcc_eh_p.a ${EH_OBJS_T} ${EH_OBJS_P}
.include <bsd.lib.mk>
diff --git a/gnu/usr.bin/binutils/Makefile.inc0 b/gnu/usr.bin/binutils/Makefile.inc0
index 7a062ba..09bda29 100644
--- a/gnu/usr.bin/binutils/Makefile.inc0
+++ b/gnu/usr.bin/binutils/Makefile.inc0
@@ -6,15 +6,19 @@
VERSION= "2.17.50 [FreeBSD] 2007-07-03"
+.if defined(TARGET_ARCH)
+TARGET_CPUARCH=${TARGET_ARCH:C/mipse[bl]/mips/:C/armeb/arm/}
+.else
+TARGET_CPUARCH=${MACHINE_CPUARCH}
+.endif
TARGET_ARCH?= ${MACHINE_ARCH}
TARGET_VENDOR?= unknown
TARGET_OS?= freebsd
-.if ${TARGET_ARCH} == "amd64"
-BINUTILS_ARCH=x86_64
-.else
-BINUTILS_ARCH=${TARGET_ARCH}
-.endif
+BINUTILS_ARCH=${TARGET_ARCH:C/amd64/x86_64/}
TARGET_TUPLE?= ${BINUTILS_ARCH}-${TARGET_VENDOR}-${TARGET_OS}
+.if ${TARGET_ARCH} == "armeb" || ${TARGET_ARCH} == "mipseb"
+TARGET_BIG_ENDIAN=t
+.endif
# RELTOP is the relative path to this point in the source or object
# tree, from any subdirectory of same. It gets extra "../" prefixes
@@ -24,28 +28,29 @@ RELTOP:= ..
RELSRC= ${RELTOP}/../../../contrib/binutils
SRCDIR= ${.CURDIR}/${RELSRC}
-.if ${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "i386" || \
- ${TARGET_ARCH} == "powerpc" || \
- (${TARGET_ARCH} == "mips" && (!defined(TARGET_ABI) || ${TARGET_ABI} != "n64"))
+.if ${TARGET_CPUARCH} == "arm" || ${TARGET_CPUARCH} == "i386" || \
+ ${TARGET_CPUARCH} == "powerpc" || \
+ (${TARGET_CPUARCH} == "mips" && \
+ (!defined(TARGET_ABI) || ${TARGET_ABI} != "n64"))
CFLAGS+= -DBFD_DEFAULT_TARGET_SIZE=32
.else
CFLAGS+= -DBFD_DEFAULT_TARGET_SIZE=64
.endif
CFLAGS+= -I.
-.if exists(${.CURDIR}/${TARGET_ARCH})
-CFLAGS+= -I${.CURDIR}/${TARGET_ARCH}
+.if exists(${.CURDIR}/${TARGET_CPUARCH})
+CFLAGS+= -I${.CURDIR}/${TARGET_CPUARCH}
.endif
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${.CURDIR}/${RELTOP}/libbfd
CFLAGS+= -I${.OBJDIR}/${RELTOP}/libbfd
CFLAGS+= -I${SRCDIR}/include
-.if exists(${.CURDIR}/${TARGET_ARCH})
-.PATH: ${.CURDIR}/${TARGET_ARCH}
+.if exists(${.CURDIR}/${TARGET_CPUARCH})
+.PATH: ${.CURDIR}/${TARGET_CPUARCH}
.endif
-ARCHS= ${TARGET_ARCH}
+ARCHS= ${TARGET_CPUARCH}
.for _arch in ${CROSS_ARCH}
.if (${ARCHS:R:M${_arch:R}} == "")
diff --git a/gnu/usr.bin/binutils/as/Makefile b/gnu/usr.bin/binutils/as/Makefile
index 7e2df54..003ce1f 100644
--- a/gnu/usr.bin/binutils/as/Makefile
+++ b/gnu/usr.bin/binutils/as/Makefile
@@ -41,7 +41,7 @@ SRCS+= app.c \
# DEO: why not used?
#SRCS+= itbl-ops.c
-.if ${TARGET_ARCH} == "mips"
+.if ${TARGET_CPUARCH} == "mips"
SRCS+= itbl-ops.c itbl-parse.y itbl-lex.l
.endif
@@ -52,7 +52,7 @@ SRCS+= tc-ppc.c
.elif ${TARGET_ARCH} == "sparc64"
SRCS+= tc-sparc.c
.else
-SRCS+= tc-${TARGET_ARCH}.c
+SRCS+= tc-${TARGET_CPUARCH}.c
.endif
.if ${TARGET_ARCH} == "sparc64"
@@ -70,7 +70,7 @@ CFLAGS+= -DTARGET_ALIAS=\"${TARGET_TUPLE}\"
CFLAGS+= -DVERSION=\"${VERSION}\"
CFLAGS+= -D_GNU_SOURCE
CFLAGS+= -I${SRCDIR}/gas -I${SRCDIR}/bfd -I${SRCDIR}/gas/config -I${SRCDIR}
-CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${TARGET_ARCH}-freebsd
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/${TARGET_CPUARCH}-freebsd
NO_SHARED?= yes
diff --git a/gnu/usr.bin/binutils/ld/Makefile.arm b/gnu/usr.bin/binutils/ld/Makefile.arm
index b4d9d69..870fcec 100644
--- a/gnu/usr.bin/binutils/ld/Makefile.arm
+++ b/gnu/usr.bin/binutils/ld/Makefile.arm
@@ -1,6 +1,6 @@
# $FreeBSD$
-.if defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "armeb"
NATIVE_EMULATION= armelfb_fbsd
.else
NATIVE_EMULATION= armelf_fbsd
diff --git a/gnu/usr.bin/binutils/ld/Makefile.mips b/gnu/usr.bin/binutils/ld/Makefile.mips
index e0d0582..de0ec94 100644
--- a/gnu/usr.bin/binutils/ld/Makefile.mips
+++ b/gnu/usr.bin/binutils/ld/Makefile.mips
@@ -1,8 +1,6 @@
# $FreeBSD$
-#xxxIMPxxx: TARGET_BIG_ENDIAN is lame. We should use the netbsd convention
-# of mipsel and mips.
-.if !defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "mipsel"
_EMULATION_ENDIAN=l
.else
_EMULATION_ENDIAN=b
diff --git a/gnu/usr.bin/binutils/libbfd/Makefile.arm b/gnu/usr.bin/binutils/libbfd/Makefile.arm
index 9633783..4910f38 100644
--- a/gnu/usr.bin/binutils/libbfd/Makefile.arm
+++ b/gnu/usr.bin/binutils/libbfd/Makefile.arm
@@ -1,6 +1,6 @@
# $FreeBSD$
-.if defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "armeb"
DEFAULT_VECTOR= bfd_elf32_bigarm_vec
.else
DEFAULT_VECTOR= bfd_elf32_littlearm_vec
@@ -14,7 +14,7 @@ SRCS+= cpu-arm.c \
elflink.c
VECS+= ${DEFAULT_VECTOR}
-.if defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "armeb"
VECS+= bfd_elf32_littlearm_vec
.else
VECS+= bfd_elf32_bigarm_vec
diff --git a/gnu/usr.bin/binutils/libbfd/Makefile.mips b/gnu/usr.bin/binutils/libbfd/Makefile.mips
index cb1e370..bf21130 100644
--- a/gnu/usr.bin/binutils/libbfd/Makefile.mips
+++ b/gnu/usr.bin/binutils/libbfd/Makefile.mips
@@ -1,15 +1,11 @@
# $FreeBSD$
-#xxxIMPxxx: TARGET_BIG_ENDIAN is lame. We should use the netbsd convention
-# of mipsel and mips.
-.if !defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "mipsel"
_EMULATION_ENDIAN=little
.else
_EMULATION_ENDIAN=big
.endif
-DEFAULT_VECTOR= bfd_elf32_tradbigmips_vec
-
.if defined(TARGET_ABI) && ${TARGET_ABI} != "o32"
.if ${TARGET_ABI} == "n32"
DEFAULT_VECTOR= bfd_elf32_ntrad${_EMULATION_ENDIAN}mips_vec
diff --git a/gnu/usr.bin/cc/Makefile.inc b/gnu/usr.bin/cc/Makefile.inc
index 994d979..9d3ee2d 100644
--- a/gnu/usr.bin/cc/Makefile.inc
+++ b/gnu/usr.bin/cc/Makefile.inc
@@ -32,9 +32,13 @@ CFLAGS+= -DLONG_TYPE_SIZE=${LONG_TYPE_SIZE}
CFLAGS+= -DCROSS_COMPILE
.endif
-.if ${TARGET_ARCH} == "mips"
-# XXX This is backwards, MIPS should default to BE.
-.if !defined(TARGET_BIG_ENDIAN)
+.if ${TARGET_ARCH} == "armeb"
+CFLAGS += -DTARGET_ENDIAN_DEFAULT=MASK_BIG_END
+.endif
+
+
+.if ${TARGET_CPUARCH} == "mips"
+.if ${TARGET_ARCH} == "mipsel"
CFLAGS += -DTARGET_ENDIAN_DEFAULT=0
.endif
diff --git a/gnu/usr.bin/cc/Makefile.tgt b/gnu/usr.bin/cc/Makefile.tgt
index 5e036bc..a1e6d08 100644
--- a/gnu/usr.bin/cc/Makefile.tgt
+++ b/gnu/usr.bin/cc/Makefile.tgt
@@ -1,16 +1,15 @@
# $FreeBSD$
-TARGET_ARCH?= ${MACHINE_ARCH}
+# These assignments duplicate much of the functionality of
+# MACHINE_CPUARCH, but there's no easy way to export make functions...
-.if ${TARGET_ARCH} == "amd64"
-GCC_CPU= i386
-.elif ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "powerpc64"
-GCC_CPU= rs6000
-.elif ${TARGET_ARCH} == "sparc64"
-GCC_CPU= sparc
+.if defined(TARGET_ARCH)
+TARGET_CPUARCH=${TARGET_ARCH:C/mipse[bl]/mips/:C/armeb/arm/}
.else
-GCC_CPU= ${TARGET_ARCH}
+TARGET_CPUARCH=${MACHINE_CPUARCH}
.endif
+TARGET_ARCH?= ${MACHINE_ARCH}
+GCC_CPU=${TARGET_CPUARCH:C/amd64/i386/:C/powerpc/rs6000/:C/sparc64/sparc/}
.if ${TARGET_ARCH} == "ia64"
TARGET_CPU_DEFAULT= MASK_GNU_AS|MASK_GNU_LD
@@ -18,7 +17,9 @@ TARGET_CPU_DEFAULT= MASK_GNU_AS|MASK_GNU_LD
.if ${TARGET_ARCH} == "sparc64"
TARGET_CPU_DEFAULT= TARGET_CPU_ultrasparc
.endif
+.if ${TARGET_ARCH} == "armeb" || ${TARGET_ARCH} == "mipseb" || ${TARGET_ARCH} == "mips64eb"
+TARGET_BIG_ENDIAN=t
+.endif
.if ${TARGET_ARCH} == "powerpc64"
TARGET_CPU_DEFAULT= \"powerpc64\"
.endif
-
diff --git a/gnu/usr.bin/cc/cc_int/Makefile b/gnu/usr.bin/cc/cc_int/Makefile
index a7ec17c..7082c3e 100644
--- a/gnu/usr.bin/cc/cc_int/Makefile
+++ b/gnu/usr.bin/cc/cc_int/Makefile
@@ -75,10 +75,6 @@ OBJS-md+= ${GCC_CPU}-c.o
# Target specific, C specific object file
C_TARGET_OBJS=
-.if ${TARGET_ARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
-CFLAGS += -DTARGET_ENDIAN_DEFAULT=MASK_BIG_END
-.endif
-
# Language-specific object files for C and Objective C.
C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
diff --git a/gnu/usr.bin/cc/cc_tools/Makefile b/gnu/usr.bin/cc/cc_tools/Makefile
index 87ad642..1ba2300 100644
--- a/gnu/usr.bin/cc/cc_tools/Makefile
+++ b/gnu/usr.bin/cc/cc_tools/Makefile
@@ -22,13 +22,13 @@ LIBIBERTY= libiberty.a
# The list of headers to go into tm.h
#
TARGET_INC+= options.h
-.if ${TARGET_ARCH} == "amd64"
+.if ${TARGET_CPUARCH} == "amd64"
TARGET_INC+= i386/biarch64.h
.endif
-.if ${TARGET_ARCH} != "arm"
+.if ${TARGET_CPUARCH} != "arm"
TARGET_INC+= ${GCC_CPU}/${GCC_CPU}.h
.endif
-.if ${TARGET_ARCH} == "i386" || ${TARGET_ARCH} == "amd64"
+.if ${TARGET_CPUARCH} == "i386" || ${TARGET_CPUARCH} == "amd64"
TARGET_INC+= ${GCC_CPU}/unix.h
TARGET_INC+= ${GCC_CPU}/att.h
.endif
@@ -38,18 +38,18 @@ TARGET_INC+= elfos.h
TARGET_INC+= freebsd-native.h
TARGET_INC+= freebsd-spec.h
TARGET_INC+= freebsd.h
-.if ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "amd64"
+.if ${TARGET_CPUARCH} != "i386" && ${TARGET_CPUARCH} != "amd64"
. if exists(${GCCDIR}/config/${GCC_CPU}/sysv4.h)
TARGET_INC+= ${GCC_CPU}/sysv4.h
. endif
.endif
-.if ${TARGET_ARCH} == "amd64"
+.if ${TARGET_CPUARCH} == "amd64"
TARGET_INC+= ${GCC_CPU}/x86-64.h
.endif
-.if ${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "mips"
+.if ${TARGET_CPUARCH} == "arm" || ${TARGET_CPUARCH} == "mips"
TARGET_INC+= ${GCC_CPU}/elf.h
.endif
-.if ${TARGET_ARCH} == "arm"
+.if ${TARGET_CPUARCH} == "arm"
TARGET_INC+= ${GCC_CPU}/aout.h
.endif
.if ${TARGET_ARCH} == "powerpc64"
@@ -57,10 +57,10 @@ TARGET_INC+= ${GCC_CPU}/biarch64.h
TARGET_INC+= ${GCC_CPU}/default64.h
.endif
TARGET_INC+= ${GCC_CPU}/freebsd.h
-.if ${TARGET_ARCH} == "amd64"
+.if ${TARGET_CPUARCH} == "amd64"
TARGET_INC+= ${GCC_CPU}/freebsd64.h
.endif
-.if ${TARGET_ARCH} == "arm"
+.if ${TARGET_CPUARCH} == "arm"
TARGET_INC+= ${GCC_CPU}/arm.h
.endif
TARGET_INC+= defaults.h
@@ -175,11 +175,11 @@ OPT_FILES+= ${GCCDIR}/config/${GCC_CPU}/${GCC_CPU}.opt
OPT_FILES+= ${.CURDIR}/${GCC_CPU}-freebsd.opt
.endif
-.if ${TARGET_ARCH} == "powerpc" || ${TARGET_ARCH} == "powerpc64"
+.if ${TARGET_CPUARCH} == "powerpc"
OPT_FILES+= ${GCCDIR}/config/${GCC_CPU}/sysv4.opt
.endif
-.if ${TARGET_ARCH} == "sparc64"
+.if ${TARGET_CPUARCH} == "sparc64"
OPT_FILES+= ${GCCDIR}/config/${GCC_CPU}/long-double-switch.opt
.endif
diff --git a/gnu/usr.bin/gdb/Makefile.inc b/gnu/usr.bin/gdb/Makefile.inc
index c230f95..2888163 100644
--- a/gnu/usr.bin/gdb/Makefile.inc
+++ b/gnu/usr.bin/gdb/Makefile.inc
@@ -16,8 +16,16 @@ OBJ_ROOT= ${.OBJDIR}/../..
OBJ_BU= ${OBJ_ROOT}/binutils
OBJ_GDB= ${OBJ_ROOT}/gdb
-TARGET_ARCH?= ${MACHINE_ARCH}
-TARGET_SUBDIR= ${BMAKE_GDB}/arch/${TARGET_ARCH}
+# These assignments duplicate much of the functionality of
+# MACHINE_CPUARCH, but there's no easy way to export make functions...
+
+.if defined(TARGET_ARCH)
+TARGET_CPUARCH=${TARGET_ARCH:C/mipse[bl]/mips/:C/armeb/arm/}
+.else
+TARGET_CPUARCH=${MACHINE_CPUARCH}
+.endif
+TARGET_ARCH?= ${MACHINE_ARCH}
+TARGET_SUBDIR= ${BMAKE_GDB}/arch/${TARGET_CPUARCH}
.if ${TARGET_ARCH} != ${MACHINE_ARCH}
GDB_CROSS_DEBUGGER=
@@ -31,7 +39,7 @@ GDB_CROSS_DEBUGGER=
CFLAGS+= -DHAVE_CONFIG_H -DRL_NO_COMPAT -DMI_OUT=1 -DTUI=1
CFLAGS+= -I.
CFLAGS+= -I${TARGET_SUBDIR}
-CFLAGS+= -I${BMAKE_BU}/libbfd -I${BMAKE_BU}/libbfd/${TARGET_ARCH}
+CFLAGS+= -I${BMAKE_BU}/libbfd -I${BMAKE_BU}/libbfd/${TARGET_CPUARCH}
CFLAGS+= -I${CNTRB_GDB}/gdb
CFLAGS+= -I${CNTRB_GDB}/gdb/config
CFLAGS+= -I${CNTRB_BU}/include
diff --git a/gnu/usr.bin/gdb/arch/mips/Makefile b/gnu/usr.bin/gdb/arch/mips/Makefile
index 54180d9..a6d4d9e 100644
--- a/gnu/usr.bin/gdb/arch/mips/Makefile
+++ b/gnu/usr.bin/gdb/arch/mips/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$
.if !defined(GDB_CROSS_DEBUGGER)
-LIBSRCS+= mipsfbsd-nat.c
+LIBSRCS+= mipsfbsd-nat.c fbsd-threads.c
.endif
LIBSRCS+= solib.c solib-svr4.c
LIBSRCS+= mips-tdep.c mipsfbsd-tdep.c fbsd-proc.c
diff --git a/gnu/usr.bin/gdb/arch/mips/init.c b/gnu/usr.bin/gdb/arch/mips/init.c
index 27631f2..491b2b3 100644
--- a/gnu/usr.bin/gdb/arch/mips/init.c
+++ b/gnu/usr.bin/gdb/arch/mips/init.c
@@ -119,6 +119,8 @@ initialize_all_files (void)
_initialize_mips_tdep ();
_initialize_mipsfbsd_tdep ();
_initialize_corelow ();
+ _initialize_solib ();
+ _initialize_svr4_solib ();
_initialize_ser_hardwire ();
_initialize_ser_pipe ();
_initialize_ser_tcp ();
@@ -130,8 +132,7 @@ initialize_all_files (void)
_initialize_kernel_u_addr ();
_initialize_infptrace ();
_initialize_inftarg ();
- _initialize_solib ();
- _initialize_svr4_solib ();
+ _initialize_thread_db ();
#if 0
_initialize_svr4_lm ();
#endif
diff --git a/gnu/usr.bin/gdb/kgdb/Makefile b/gnu/usr.bin/gdb/kgdb/Makefile
index 955394a..1372f17 100644
--- a/gnu/usr.bin/gdb/kgdb/Makefile
+++ b/gnu/usr.bin/gdb/kgdb/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$
PROG= kgdb${GDB_SUFFIX}
-SRCS= main.c kld.c kthr.c trgt.c trgt_${TARGET_ARCH}.c
+SRCS= main.c kld.c kthr.c trgt.c trgt_${TARGET_CPUARCH}.c
WARNS?= 2
BULIBS= ${OBJ_BU}/libbfd/libbfd.a ${OBJ_BU}/libopcodes/libopcodes.a \
diff --git a/gnu/usr.bin/gdb/kgdb/trgt_mips.c b/gnu/usr.bin/gdb/kgdb/trgt_mips.c
index 9782222..423cacd 100644
--- a/gnu/usr.bin/gdb/kgdb/trgt_mips.c
+++ b/gnu/usr.bin/gdb/kgdb/trgt_mips.c
@@ -46,11 +46,16 @@ __FBSDID("$FreeBSD$");
#include <frame-unwind.h>
#include <mips-tdep.h>
+#ifndef CROSS_DEBUGGER
+#include <machine/pcb.h>
+#endif
+
#include "kgdb.h"
void
kgdb_trgt_fetch_registers(int regno __unused)
{
+#ifndef CROSS_DEBUGGER
struct kthr *kt;
struct pcb pcb;
@@ -61,24 +66,27 @@ kgdb_trgt_fetch_registers(int regno __unused)
warnx("kvm_read: %s", kvm_geterr(kvm));
memset(&pcb, 0, sizeof(pcb));
}
- supply_register(MIPS_S0_REGNUM, (char *)&pcb.pcb_context[0]);
- supply_register(MIPS_S1_REGNUM, (char *)&pcb.pcb_context[1]);
- supply_register(MIPS_S2_REGNUM, (char *)&pcb.pcb_context[2]);
- supply_register(MIPS_S3_REGNUM, (char *)&pcb.pcb_context[3]);
- supply_register(MIPS_S4_REGNUM, (char *)&pcb.pcb_context[4]);
- supply_register(MIPS_S5_REGNUM, (char *)&pcb.pcb_context[5]);
- supply_register(MIPS_S6_REGNUM, (char *)&pcb.pcb_context[6]);
- supply_register(MIPS_S7_REGNUM, (char *)&pcb.pcb_context[7]);
- supply_register(MIPS_SP_REGNUM, (char *)&pcb.pcb_context[8]);
- supply_register(MIPS_FP_REGNUM, (char *)&pcb.pcb_context[9]);
- supply_register(MIPS_RA_REGNUM, (char *)&pcb.pcb_context[10]);
+
+ supply_register(MIPS_S0_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S0]);
+ supply_register(MIPS_S1_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S1]);
+ supply_register(MIPS_S2_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S2]);
+ supply_register(MIPS_S3_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S3]);
+ supply_register(MIPS_S4_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S4]);
+ supply_register(MIPS_S5_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S5]);
+ supply_register(MIPS_S6_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S6]);
+ supply_register(MIPS_S7_REGNUM, (char *)&pcb.pcb_context[PCB_REG_S7]);
+ supply_register(MIPS_SP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_SP]);
+ supply_register(MIPS_FP_REGNUM, (char *)&pcb.pcb_context[PCB_REG_GP]);
+ supply_register(MIPS_RA_REGNUM, (char *)&pcb.pcb_context[PCB_REG_RA]);
+ supply_register(MIPS_EMBED_PC_REGNUM, (char *)&pcb.pcb_context[PCB_REG_PC]);
+#endif
}
void
kgdb_trgt_store_registers(int regno __unused)
{
- fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__);
+ fprintf_unfiltered(gdb_stderr, "Unimplemented function: %s\n", __func__);
}
void
@@ -86,6 +94,7 @@ kgdb_trgt_new_objfile(struct objfile *objfile)
{
}
+#ifndef CROSS_DEBUGGER
struct kgdb_frame_cache {
CORE_ADDR pc;
CORE_ADDR sp;
@@ -127,7 +136,7 @@ static int kgdb_trgt_frame_offset[] = {
};
static struct kgdb_frame_cache *
-kgdb_trgt_frame_cache(struct frame_info *next_frame __unused, void **this_cache __unused)
+kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache)
{
char buf[MAX_REGISTER_SIZE];
struct kgdb_frame_cache *cache;
@@ -190,10 +199,12 @@ static const struct frame_unwind kgdb_trgt_trapframe_unwind = {
&kgdb_trgt_trapframe_this_id,
&kgdb_trgt_trapframe_prev_register
};
+#endif
const struct frame_unwind *
-kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame __unused)
+kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame)
{
+#ifndef CROSS_DEBUGGER
char *pname;
CORE_ADDR pc;
@@ -207,6 +218,6 @@ kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame __unused)
(strcmp(pname, "MipsUserIntr") == 0) ||
(strcmp(pname, "MipsUserGenException") == 0))
return (&kgdb_trgt_trapframe_unwind);
- /* printf("%s: %llx =%s\n", __func__, pc, pname); */
+#endif
return (NULL);
}
diff --git a/gnu/usr.bin/gdb/libgdb/Makefile b/gnu/usr.bin/gdb/libgdb/Makefile
index 8c22a1a..bb18a8e 100644
--- a/gnu/usr.bin/gdb/libgdb/Makefile
+++ b/gnu/usr.bin/gdb/libgdb/Makefile
@@ -1,6 +1,14 @@
# $FreeBSD$
-TARGET_ARCH?= ${MACHINE_ARCH}
+# These assignments duplicate much of the functionality of
+# MACHINE_CPUARCH, but there's no easy way to export make functions...
+
+.if defined(TARGET_ARCH)
+TARGET_CPUARCH=${TARGET_ARCH:C/mipse[bl]/mips/:C/armeb/arm/}
+.else
+TARGET_CPUARCH=${MACHINE_CPUARCH}
+.endif
+TARGET_ARCH?= ${MACHINE_ARCH}
LIB= gdb
INTERNALLIB=
diff --git a/lib/Makefile b/lib/Makefile
index 75de092..e6e3cf0 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -34,6 +34,7 @@ SUBDIR_ORDERED= ${_csu} \
libbsm \
libauditd \
libcom_err \
+ libcompiler_rt \
libcrypt \
libelf \
libkvm \
@@ -53,6 +54,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
libarchive \
${_libatm} \
libbegemot \
+ libblocksruntime \
${_libbluetooth} \
${_libbsnmp} \
libbz2 \
diff --git a/lib/libarchive/archive_read_support_format_zip.c b/lib/libarchive/archive_read_support_format_zip.c
index 4a24cc8..0fa1fa3 100644
--- a/lib/libarchive/archive_read_support_format_zip.c
+++ b/lib/libarchive/archive_read_support_format_zip.c
@@ -128,6 +128,7 @@ static int archive_read_format_zip_read_data(struct archive_read *,
static int archive_read_format_zip_read_data_skip(struct archive_read *a);
static int archive_read_format_zip_read_header(struct archive_read *,
struct archive_entry *);
+static int search_next_signature(struct archive_read *);
static int zip_read_data_deflate(struct archive_read *a, const void **buff,
size_t *size, off_t *offset);
static int zip_read_data_none(struct archive_read *a, const void **buff,
@@ -317,10 +318,17 @@ archive_read_format_zip_read_header(struct archive_read *a,
signature = (const char *)h;
}
+ /* If we don't see a PK signature here, scan forward. */
if (signature[0] != 'P' || signature[1] != 'K') {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
- "Bad ZIP file");
- return (ARCHIVE_FATAL);
+ r = search_next_signature(a);
+ if (r != ARCHIVE_OK) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Bad ZIP file");
+ return (ARCHIVE_FATAL);
+ }
+ if ((h = __archive_read_ahead(a, 4, NULL)) == NULL)
+ return (ARCHIVE_FATAL);
+ signature = (const char *)h;
}
/*
@@ -375,6 +383,42 @@ archive_read_format_zip_read_header(struct archive_read *a,
}
static int
+search_next_signature(struct archive_read *a)
+{
+ const void *h;
+ const char *p, *q;
+ size_t skip;
+ ssize_t bytes;
+ int64_t skipped = 0;
+
+ for (;;) {
+ h = __archive_read_ahead(a, 4, &bytes);
+ if (h == NULL)
+ return (ARCHIVE_FATAL);
+ p = h;
+ q = p + bytes;
+
+ while (p + 4 <= q) {
+ if (p[0] == 'P' && p[1] == 'K') {
+ if ((p[2] == '\001' && p[3] == '\002')
+ || (p[2] == '\003' && p[3] == '\004')
+ || (p[2] == '\005' && p[3] == '\006')
+ || (p[2] == '\007' && p[3] == '\010')
+ || (p[2] == '0' && p[3] == '0')) {
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ return (ARCHIVE_OK);
+ }
+ }
+ ++p;
+ }
+ skip = p - (const char *)h;
+ __archive_read_consume(a, skip);
+ skipped += skip;
+ }
+}
+
+static int
zip_read_file_header(struct archive_read *a, struct archive_entry *entry,
struct zip *zip)
{
@@ -888,6 +932,9 @@ process_extra(const void* extra, struct zip* zip)
if (datasize >= 4)
zip->gid = archive_le16dec(p + offset + 2);
break;
+ case 0x7875:
+ /* Info-Zip Unix Extra Field (type 3) "ux". */
+ break;
default:
break;
}
diff --git a/lib/libarchive/test/test_compat_zip.c b/lib/libarchive/test/test_compat_zip.c
index fefc6fe..adb377c 100644
--- a/lib/libarchive/test/test_compat_zip.c
+++ b/lib/libarchive/test/test_compat_zip.c
@@ -71,10 +71,43 @@ finish:
#endif
}
+/*
+ * Verify that we skip junk between entries. The compat_zip_2.zip file
+ * has several bytes of junk between 'file1' and 'file2'. Such
+ * junk is routinely introduced by some Zip writers when they manipulate
+ * existing zip archives.
+ */
+static void
+test_compat_zip_2(void)
+{
+ char name[] = "test_compat_zip_2.zip";
+ struct archive_entry *ae;
+ struct archive *a;
+
+ assert((a = archive_read_new()) != NULL);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+ extract_reference_file(name);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240));
+
+ /* Read first entry. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("file1", archive_entry_pathname(ae));
+
+ /* Read first entry. */
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+ assertEqualString("file2", archive_entry_pathname(ae));
+
+ assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+ assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+
DEFINE_TEST(test_compat_zip)
{
test_compat_zip_1();
+ test_compat_zip_2();
}
diff --git a/lib/libarchive/test/test_compat_zip_2.zip.uu b/lib/libarchive/test/test_compat_zip_2.zip.uu
new file mode 100644
index 0000000..c33e9d9
--- /dev/null
+++ b/lib/libarchive/test/test_compat_zip_2.zip.uu
@@ -0,0 +1,10 @@
+$FreeBSD$
+
+begin 644 test_compat_zip_2.zip
+M4$L#!`H``````'V59CT````````````````%````9FEL93$M2E5.2RU02P,$
+M"@``````@95F/<>D!,D&````!@````4```!F:6QE,F9I;&4R"E!+`0(>`PH`
+M`````'V59CT````````````````%``````````````"D@0````!F:6QE,5!+
+M`0(>`PH``````(&59CW'I`3)!@````8````%``````````````"D@2D```!F
+::6QE,E!+!08``````@`"`&8```!2````````
+`
+end
diff --git a/lib/libblocksruntime/Makefile b/lib/libblocksruntime/Makefile
new file mode 100644
index 0000000..01a78fe
--- /dev/null
+++ b/lib/libblocksruntime/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+LIB= BlocksRuntime
+SHLIB_MAJOR=0
+CFLAGS+=-I${.CURDIR}
+WARNS?= 2
+
+.PATH: ${.CURDIR}/../../contrib/compiler-rt/BlocksRuntime
+
+INCS= Block.h Block_private.h
+SRCS= data.c runtime.c
+
+.include <bsd.lib.mk>
diff --git a/lib/libblocksruntime/config.h b/lib/libblocksruntime/config.h
new file mode 100644
index 0000000..36418d3
--- /dev/null
+++ b/lib/libblocksruntime/config.h
@@ -0,0 +1,14 @@
+/* $FreeBSD$ */
+
+/* #undef HAVE_SYS_BYTEORDER_H */
+/* #undef HAVE_AVAILABILITY_MACROS_H */
+/* #undef HAVE_TARGET_CONDITIONALS_H */
+/* #undef HAVE_LIBKERN_OSATOMIC_H */
+
+#define HAVE_SYSCONF 1
+
+/* #undef HAVE_OSATOMIC_COMPARE_AND_SWAP_INT */
+/* #undef HAVE_OSATOMIC_COMPARE_AND_SWAP_LONG */
+
+#define HAVE_SYNC_BOOL_COMPARE_AND_SWAP_INT 1
+#define HAVE_SYNC_BOOL_COMPARE_AND_SWAP_LONG 1
diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
new file mode 100644
index 0000000..2da28aa
--- /dev/null
+++ b/lib/libcompiler_rt/Makefile
@@ -0,0 +1,157 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= compiler_rt
+NO_PIC=
+WARNS?= 2
+
+CFLAGS+=${PICFLAG} -fvisibility=hidden -DVISIBILITY_HIDDEN
+
+.if ${MACHINE_CPUARCH} == "amd64"
+CRTARCH=x86_64
+.else
+CRTARCH=${MACHINE_CPUARCH}
+.endif
+
+CRTSRC=${.CURDIR}/../../contrib/compiler-rt/lib
+
+.PATH: ${CRTSRC}/${CRTARCH} ${CRTSRC}
+
+SRCF= absvdi2 \
+ absvsi2 \
+ absvti2 \
+ addvdi3 \
+ addvsi3 \
+ addvti3 \
+ ashldi3 \
+ ashlti3 \
+ ashrdi3 \
+ ashrti3 \
+ clear_cache \
+ clzdi2 \
+ clzsi2 \
+ clzti2 \
+ cmpdi2 \
+ cmpti2 \
+ comparedf2 \
+ comparesf2 \
+ ctzdi2 \
+ ctzsi2 \
+ ctzti2 \
+ divdc3 \
+ divdi3 \
+ divsc3 \
+ divti3 \
+ divxc3 \
+ enable_execute_stack \
+ eprintf \
+ ffsdi2 \
+ ffsti2 \
+ fixdfdi \
+ fixdfti \
+ fixsfdi \
+ fixsfti \
+ fixunsdfdi \
+ fixunsdfsi \
+ fixunsdfti \
+ fixunssfdi \
+ fixunssfsi \
+ fixunssfti \
+ fixunsxfdi \
+ fixunsxfsi \
+ fixunsxfti \
+ fixxfdi \
+ fixxfti \
+ floatdidf \
+ floatdisf \
+ floatdixf \
+ floattidf \
+ floattisf \
+ floattixf \
+ floatundidf \
+ floatundisf \
+ floatundixf \
+ floatunsidf \
+ floatunsisf \
+ floatuntidf \
+ floatuntisf \
+ floatuntixf \
+ lshrdi3 \
+ lshrti3 \
+ moddi3 \
+ modti3 \
+ muldc3 \
+ muldi3 \
+ mulsc3 \
+ multi3 \
+ mulvdi3 \
+ mulvsi3 \
+ mulvti3 \
+ mulxc3 \
+ negdf2 \
+ negdi2 \
+ negsf2 \
+ negti2 \
+ negvdi2 \
+ negvsi2 \
+ negvti2 \
+ paritydi2 \
+ paritysi2 \
+ parityti2 \
+ popcountdi2 \
+ popcountsi2 \
+ popcountti2 \
+ powidf2 \
+ powisf2 \
+ powitf2 \
+ powixf2 \
+ subvdi3 \
+ subvsi3 \
+ subvti3 \
+ trampoline_setup \
+ ucmpdi2 \
+ ucmpti2 \
+ udivdi3 \
+ udivmoddi4 \
+ udivmodti4 \
+ udivti3 \
+ umoddi3 \
+ umodti3
+
+# These are already shipped by libc.a on arm and mips
+.if ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
+SRCF+= adddf3 \
+ addsf3 \
+ divdf3 \
+ divsf3 \
+ divsi3 \
+ extendsfdf2 \
+ fixdfsi \
+ fixsfsi \
+ floatsidf \
+ floatsisf \
+ modsi3 \
+ muldf3 \
+ mulsf3 \
+ truncdfsf2 \
+ udivsi3 \
+ umodsi3
+.endif
+
+.for file in ${SRCF}
+. if ${MACHINE_CPUARCH} != "arm" && exists(${CRTSRC}/${CRTARCH}/${file}.S)
+SRCS+= ${file}.S
+. else
+SRCS+= ${file}.c
+. endif
+.endfor
+
+.if ${MK_INSTALLLIB} != "no"
+SYMLINKS+=libcompiler_rt.a ${LIBDIR}/libgcc.a
+.endif
+.if ${MK_PROFILE} != "no"
+SYMLINKS+=libcompiler_rt_p.a ${LIBDIR}/libgcc_p.a
+.endif
+
+.include <bsd.lib.mk>
diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile
index ea5e09f..24a6e32 100644
--- a/lib/libkvm/Makefile
+++ b/lib/libkvm/Makefile
@@ -20,7 +20,7 @@ WARNS?= 0
SRCS= kvm.c kvm_${KVM_ARCH}.c kvm_cptime.c kvm_file.c kvm_getloadavg.c \
kvm_getswapinfo.c kvm_pcpu.c kvm_proc.c kvm_vnet.c
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" || \
- ${MACHINE_CPUARCH} == "arm"
+ ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
SRCS+= kvm_minidump_${KVM_ARCH}.c
.endif
INCS= kvm.h
diff --git a/lib/libkvm/kvm_minidump_amd64.c b/lib/libkvm/kvm_minidump_amd64.c
index 8f48f98..15630b1 100644
--- a/lib/libkvm/kvm_minidump_amd64.c
+++ b/lib/libkvm/kvm_minidump_amd64.c
@@ -67,7 +67,7 @@ struct vmstate {
struct minidumphdr hdr;
void *hpt_head[HPT_SIZE];
uint64_t *bitmap;
- uint64_t *ptemap;
+ uint64_t *page_map;
};
static void
@@ -127,8 +127,8 @@ _kvm_minidump_freevtop(kvm_t *kd)
if (vm->bitmap)
free(vm->bitmap);
- if (vm->ptemap)
- free(vm->ptemap);
+ if (vm->page_map)
+ free(vm->page_map);
free(vm);
kd->vmst = NULL;
}
@@ -156,7 +156,12 @@ _kvm_minidump_initvtop(kvm_t *kd)
_kvm_err(kd, kd->program, "not a minidump for this platform");
return (-1);
}
- if (vmst->hdr.version != MINIDUMP_VERSION) {
+
+ /*
+ * NB: amd64 minidump header is binary compatible between version 1
+ * and version 2; this may not be the case for the future versions.
+ */
+ if (vmst->hdr.version != MINIDUMP_VERSION && vmst->hdr.version != 1) {
_kvm_err(kd, kd->program, "wrong minidump version. expected %d got %d",
MINIDUMP_VERSION, vmst->hdr.version);
return (-1);
@@ -177,17 +182,17 @@ _kvm_minidump_initvtop(kvm_t *kd)
}
off += round_page(vmst->hdr.bitmapsize);
- vmst->ptemap = _kvm_malloc(kd, vmst->hdr.ptesize);
- if (vmst->ptemap == NULL) {
- _kvm_err(kd, kd->program, "cannot allocate %d bytes for ptemap", vmst->hdr.ptesize);
+ vmst->page_map = _kvm_malloc(kd, vmst->hdr.pmapsize);
+ if (vmst->page_map == NULL) {
+ _kvm_err(kd, kd->program, "cannot allocate %d bytes for page_map", vmst->hdr.pmapsize);
return (-1);
}
- if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
- vmst->hdr.ptesize) {
- _kvm_err(kd, kd->program, "cannot read %d bytes for ptemap", vmst->hdr.ptesize);
+ if (pread(kd->pmfd, vmst->page_map, vmst->hdr.pmapsize, off) !=
+ vmst->hdr.pmapsize) {
+ _kvm_err(kd, kd->program, "cannot read %d bytes for page_map", vmst->hdr.pmapsize);
return (-1);
}
- off += vmst->hdr.ptesize;
+ off += vmst->hdr.pmapsize;
/* build physical address hash table for sparse pages */
inithash(kd, vmst->bitmap, vmst->hdr.bitmapsize, off);
@@ -196,7 +201,7 @@ _kvm_minidump_initvtop(kvm_t *kd)
}
static int
-_kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa)
+_kvm_minidump_vatop_v1(kvm_t *kd, u_long va, off_t *pa)
{
struct vmstate *vm;
u_long offset;
@@ -211,7 +216,7 @@ _kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa)
if (va >= vm->hdr.kernbase) {
pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;
- pte = vm->ptemap[pteindex];
+ pte = vm->page_map[pteindex];
if (((u_long)pte & PG_V) == 0) {
_kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
goto invalid;
@@ -243,6 +248,78 @@ invalid:
return (0);
}
+static int
+_kvm_minidump_vatop(kvm_t *kd, u_long va, off_t *pa)
+{
+ pt_entry_t pt[NPTEPG];
+ struct vmstate *vm;
+ u_long offset;
+ pd_entry_t pde;
+ pd_entry_t pte;
+ u_long pteindex;
+ u_long pdeindex;
+ int i;
+ u_long a;
+ off_t ofs;
+
+ vm = kd->vmst;
+ offset = va & PAGE_MASK;
+
+ if (va >= vm->hdr.kernbase) {
+ pdeindex = (va - vm->hdr.kernbase) >> PDRSHIFT;
+ pde = vm->page_map[pdeindex];
+ if (((u_long)pde & PG_V) == 0) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: pde not valid");
+ goto invalid;
+ }
+ if ((pde & PG_PS) == 0) {
+ a = pde & PG_FRAME;
+ ofs = hpt_find(kd, a);
+ if (ofs == -1) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: pt physical address 0x%lx not in minidump", a);
+ goto invalid;
+ }
+ if (pread(kd->pmfd, &pt, PAGE_SIZE, ofs) != PAGE_SIZE) {
+ _kvm_err(kd, kd->program, "cannot read %d bytes for pt", PAGE_SIZE);
+ return (-1);
+ }
+ pteindex = (va >> PAGE_SHIFT) & ((1ul << NPTEPGSHIFT) - 1);
+ pte = pt[pteindex];
+ if (((u_long)pte & PG_V) == 0) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
+ goto invalid;
+ }
+ a = pte & PG_FRAME;
+ } else {
+ a = pde & PG_PS_FRAME;
+ a += (va & PDRMASK) ^ offset;
+ }
+ ofs = hpt_find(kd, a);
+ if (ofs == -1) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: physical address 0x%lx not in minidump", a);
+ goto invalid;
+ }
+ *pa = ofs + offset;
+ return (PAGE_SIZE - offset);
+ } else if (va >= vm->hdr.dmapbase && va < vm->hdr.dmapend) {
+ a = (va - vm->hdr.dmapbase) & ~PAGE_MASK;
+ ofs = hpt_find(kd, a);
+ if (ofs == -1) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: direct map address 0x%lx not in minidump", va);
+ goto invalid;
+ }
+ *pa = ofs + offset;
+ return (PAGE_SIZE - offset);
+ } else {
+ _kvm_err(kd, kd->program, "_kvm_vatop: virtual address 0x%lx not minidumped", va);
+ goto invalid;
+ }
+
+invalid:
+ _kvm_err(kd, 0, "invalid address (0x%lx)", va);
+ return (0);
+}
+
int
_kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa)
{
@@ -251,5 +328,8 @@ _kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa)
_kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
return (0);
}
- return (_kvm_minidump_vatop(kd, va, pa));
+ if (((struct vmstate *)kd->vmst)->hdr.version == 1)
+ return (_kvm_minidump_vatop_v1(kd, va, pa));
+ else
+ return (_kvm_minidump_vatop(kd, va, pa));
}
diff --git a/lib/libkvm/kvm_minidump_mips.c b/lib/libkvm/kvm_minidump_mips.c
new file mode 100644
index 0000000..c82e249
--- /dev/null
+++ b/lib/libkvm/kvm_minidump_mips.c
@@ -0,0 +1,275 @@
+/*-
+ * Copyright (c) 2010 Oleksandr Tymoshenko
+ * Copyright (c) 2008 Semihalf, Grzegorz Bernacki
+ * Copyright (c) 2006 Peter Wemm
+ *
+ * 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.
+ *
+ * From: FreeBSD: src/lib/libkvm/kvm_minidump_arm.c r214223
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * MIPS machine dependent routines for kvm and minidumps.
+ */
+
+#include <sys/param.h>
+#include <sys/user.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/fnv_hash.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <nlist.h>
+#include <kvm.h>
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+
+#include <machine/elf.h>
+#include <machine/cpufunc.h>
+#include <machine/minidump.h>
+
+#include <limits.h>
+
+#include "kvm_private.h"
+
+struct hpte {
+ struct hpte *next;
+ uint64_t pa;
+ int64_t off;
+};
+
+#define HPT_SIZE 1024
+
+/* minidump must be the first field */
+struct vmstate {
+ int minidump; /* 1 = minidump mode */
+ struct minidumphdr hdr;
+ void *hpt_head[HPT_SIZE];
+ uint32_t *bitmap;
+ void *ptemap;
+};
+
+static void
+hpt_insert(kvm_t *kd, uint64_t pa, int64_t off)
+{
+ struct hpte *hpte;
+ uint32_t fnv = FNV1_32_INIT;
+
+ fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+ fnv &= (HPT_SIZE - 1);
+ hpte = malloc(sizeof(*hpte));
+ hpte->pa = pa;
+ hpte->off = off;
+ hpte->next = kd->vmst->hpt_head[fnv];
+ kd->vmst->hpt_head[fnv] = hpte;
+}
+
+static int64_t
+hpt_find(kvm_t *kd, uint64_t pa)
+{
+ struct hpte *hpte;
+ uint32_t fnv = FNV1_32_INIT;
+
+ fnv = fnv_32_buf(&pa, sizeof(pa), fnv);
+ fnv &= (HPT_SIZE - 1);
+ for (hpte = kd->vmst->hpt_head[fnv]; hpte != NULL; hpte = hpte->next)
+ if (pa == hpte->pa)
+ return (hpte->off);
+
+ return (-1);
+}
+
+static int
+inithash(kvm_t *kd, uint32_t *base, int len, off_t off)
+{
+ uint64_t idx, pa;
+ uint32_t bit, bits;
+
+ for (idx = 0; idx < len / sizeof(*base); idx++) {
+ bits = base[idx];
+ while (bits) {
+ bit = ffs(bits) - 1;
+ bits &= ~(1ul << bit);
+ pa = (idx * sizeof(*base) * NBBY + bit) * PAGE_SIZE;
+ hpt_insert(kd, pa, off);
+ off += PAGE_SIZE;
+ }
+ }
+
+ return (off);
+}
+
+void
+_kvm_minidump_freevtop(kvm_t *kd)
+{
+ struct vmstate *vm = kd->vmst;
+
+ if (vm->bitmap)
+ free(vm->bitmap);
+ if (vm->ptemap)
+ free(vm->ptemap);
+ free(vm);
+ kd->vmst = NULL;
+}
+
+int
+_kvm_minidump_initvtop(kvm_t *kd)
+{
+ u_long pa;
+ struct vmstate *vmst;
+ off_t off;
+
+ vmst = _kvm_malloc(kd, sizeof(*vmst));
+ if (vmst == 0) {
+ _kvm_err(kd, kd->program, "cannot allocate vm");
+ return (-1);
+ }
+
+ kd->vmst = vmst;
+ vmst->minidump = 1;
+
+ off = lseek(kd->pmfd, 0, SEEK_CUR);
+ if (pread(kd->pmfd, &vmst->hdr,
+ sizeof(vmst->hdr), 0) != sizeof(vmst->hdr)) {
+ _kvm_err(kd, kd->program, "cannot read dump header");
+ return (-1);
+ }
+
+ if (strncmp(MINIDUMP_MAGIC, vmst->hdr.magic,
+ sizeof(vmst->hdr.magic)) != 0) {
+ _kvm_err(kd, kd->program, "not a minidump for this platform");
+ return (-1);
+ }
+ if (vmst->hdr.version != MINIDUMP_VERSION) {
+ _kvm_err(kd, kd->program, "wrong minidump version. "
+ "Expected %d got %d", MINIDUMP_VERSION, vmst->hdr.version);
+ return (-1);
+ }
+
+ /* Skip header and msgbuf */
+ off = PAGE_SIZE + round_page(vmst->hdr.msgbufsize);
+
+ vmst->bitmap = _kvm_malloc(kd, vmst->hdr.bitmapsize);
+ if (vmst->bitmap == NULL) {
+ _kvm_err(kd, kd->program, "cannot allocate %d bytes for "
+ "bitmap", vmst->hdr.bitmapsize);
+ return (-1);
+ }
+
+ if (pread(kd->pmfd, vmst->bitmap, vmst->hdr.bitmapsize, off) !=
+ vmst->hdr.bitmapsize) {
+ _kvm_err(kd, kd->program, "cannot read %d bytes for page bitmap",
+ vmst->hdr.bitmapsize);
+ return (-1);
+ }
+ off += round_page(vmst->hdr.bitmapsize);
+
+ vmst->ptemap = _kvm_malloc(kd, vmst->hdr.ptesize);
+ if (vmst->ptemap == NULL) {
+ _kvm_err(kd, kd->program, "cannot allocate %d bytes for "
+ "ptemap", vmst->hdr.ptesize);
+ return (-1);
+ }
+
+ if (pread(kd->pmfd, vmst->ptemap, vmst->hdr.ptesize, off) !=
+ vmst->hdr.ptesize) {
+ _kvm_err(kd, kd->program, "cannot read %d bytes for ptemap",
+ vmst->hdr.ptesize);
+ return (-1);
+ }
+
+ off += vmst->hdr.ptesize;
+
+ /* Build physical address hash table for sparse pages */
+ inithash(kd, vmst->bitmap, vmst->hdr.bitmapsize, off);
+
+ return (0);
+}
+
+int
+_kvm_minidump_kvatop(kvm_t *kd, u_long va, off_t *pa)
+{
+ struct vmstate *vm;
+ pt_entry_t pte;
+ u_long offset, pteindex, a;
+ off_t ofs;
+ pt_entry_t *ptemap;
+ int i;
+
+ if (ISALIVE(kd)) {
+ _kvm_err(kd, 0, "kvm_kvatop called in live kernel!");
+ return (0);
+ }
+
+ offset = va & PAGE_MASK;
+ /* Operate with page-aligned address */
+ va &= ~PAGE_MASK;
+
+ vm = kd->vmst;
+ ptemap = vm->ptemap;
+
+#if defined(__mips_n64)
+ if (va >= MIPS_XKPHYS_START && va < MIPS_XKPHYS_END)
+ a = (MIPS_XKPHYS_TO_PHYS(va));
+ else
+#endif
+ if (va >= MIPS_KSEG0_START && va < MIPS_KSEG0_END)
+ a = (MIPS_KSEG0_TO_PHYS(va));
+ else if (va >= MIPS_KSEG1_START && va < MIPS_KSEG1_END)
+ a = (MIPS_KSEG1_TO_PHYS(va));
+ else if (va >= vm->hdr.kernbase) {
+ pteindex = (va - vm->hdr.kernbase) >> PAGE_SHIFT;
+ pte = ptemap[pteindex];
+ if (!pte) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: pte not valid");
+ goto invalid;
+ }
+
+ a = TLBLO_PTE_TO_PA(pte);
+
+ } else {
+ _kvm_err(kd, kd->program, "_kvm_vatop: virtual address 0x%lx "
+ "not minidumped", va);
+ return (0);
+ }
+
+ ofs = hpt_find(kd, a);
+ if (ofs == -1) {
+ _kvm_err(kd, kd->program, "_kvm_vatop: physical "
+ "address 0x%lx not in minidump", a);
+ goto invalid;
+ }
+
+ *pa = ofs + offset;
+ return (PAGE_SIZE - offset);
+
+
+invalid:
+ _kvm_err(kd, 0, "invalid address (0x%lx)", va);
+ return (0);
+}
diff --git a/lib/libkvm/kvm_mips.c b/lib/libkvm/kvm_mips.c
index d311c84..d311b9e 100644
--- a/lib/libkvm/kvm_mips.c
+++ b/lib/libkvm/kvm_mips.c
@@ -49,29 +49,62 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <kvm.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include "kvm_private.h"
+/* minidump must be the first item! */
+struct vmstate {
+ int minidump; /* 1 = minidump mode */
+ void *mmapbase;
+ size_t mmapsize;
+};
+
void
_kvm_freevtop(kvm_t *kd)
{
-
- _kvm_err(kd, 0, "Unimplemented function");
+ if (kd->vmst != 0) {
+ if (kd->vmst->minidump)
+ return (_kvm_minidump_freevtop(kd));
+ if (kd->vmst->mmapbase != NULL)
+ munmap(kd->vmst->mmapbase, kd->vmst->mmapsize);
+ free(kd->vmst);
+ kd->vmst = NULL;
+ }
}
int
_kvm_initvtop(kvm_t *kd)
{
+ char minihdr[8];
- _kvm_err(kd, 0, "Unimplemented function");
- return (0);
+ if (!kd->rawdump) {
+ if (pread(kd->pmfd, &minihdr, 8, 0) == 8) {
+ if (memcmp(&minihdr, "minidump", 8) == 0)
+ return (_kvm_minidump_initvtop(kd));
+ } else {
+ _kvm_err(kd, kd->program, "cannot read header");
+ return (-1);
+ }
+ }
+
+ _kvm_err(kd, 0, "_kvm_initvtop: Unsupported image type");
+ return (-1);
}
int
-_kvm_kvatop(kvm_t *kd, u_long va __unused, off_t *pa __unused)
+_kvm_kvatop(kvm_t *kd, u_long va , off_t *pa)
{
- _kvm_err(kd, 0, "Unimplemented function");
+ u_long offset = va & (PAGE_SIZE - 1);
+ struct vmstate *vm = kd->vmst;
+
+ if (kd->vmst->minidump)
+ return _kvm_minidump_kvatop(kd, va, pa);
+
+
+ _kvm_err(kd, 0, "_kvm_kvatop: Unsupported image type");
return (0);
}
@@ -81,10 +114,8 @@ _kvm_kvatop(kvm_t *kd, u_long va __unused, off_t *pa __unused)
* have to deal with these NOT being constants! (i.e. m68k)
*/
int
-_kvm_mdopen(kd)
- kvm_t *kd;
+_kvm_mdopen(kvm_t *kd __unused)
{
- _kvm_err(kd, 0, "Unimplemented function");
return (0);
}
diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h
index 69b1658..b3eeea7 100644
--- a/lib/libkvm/kvm_private.h
+++ b/lib/libkvm/kvm_private.h
@@ -104,7 +104,8 @@ uintptr_t _kvm_vnet_validaddr(kvm_t *, uintptr_t);
int _kvm_dpcpu_initialized(kvm_t *, int);
uintptr_t _kvm_dpcpu_validaddr(kvm_t *, uintptr_t);
-#if defined(__amd64__) || defined(__i386__) || defined(__arm__)
+#if defined(__amd64__) || defined(__i386__) || defined(__arm__) || \
+ defined(__mips__)
void _kvm_minidump_freevtop(kvm_t *);
int _kvm_minidump_initvtop(kvm_t *);
int _kvm_minidump_kvatop(kvm_t *, u_long, off_t *);
diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c
index d6d0558..5613dd1 100644
--- a/libexec/tftpd/tftp-utils.c
+++ b/libexec/tftpd/tftp-utils.c
@@ -100,7 +100,7 @@ unmappedaddr(struct sockaddr_in6 *sin6)
sin4->sin_len = sizeof(struct sockaddr_in);
}
-/* Get a field from a \0 seperated string */
+/* Get a field from a \0 separated string */
ssize_t
get_field(int peer, char *buffer, ssize_t size)
{
diff --git a/release/sparc64/boot_crunch.conf b/release/sparc64/boot_crunch.conf
index cd93c80..7deaee8 100644
--- a/release/sparc64/boot_crunch.conf
+++ b/release/sparc64/boot_crunch.conf
@@ -15,6 +15,7 @@ srcdirs /usr/src/sbin
progs camcontrol
progs dhclient
progs fsck_ffs
+progs geom
progs ifconfig
progs mount_nfs
progs newfs
@@ -23,6 +24,8 @@ progs rtsol
progs tunefs
ln fsck_ffs fsck_4.2bsd
ln fsck_ffs fsck_ufs
+ln geom glabel
+ln geom gpart
srcdirs /usr/src/usr.bin
progs cpio
@@ -40,5 +43,5 @@ progs sysinstall
progs usbconfig
libs -ll -ledit -lutil -lmd -lcrypt -lftpio -lz -lnetgraph
-libs -ldialog -lncurses -ldisk -lcam -lsbuf -lufs -lbsdxml
+libs -ldialog -lncurses -ldisk -lcam -lsbuf -lufs -lgeom -lbsdxml
libs -larchive -lcrypto -lbz2 -llzma -lusb -ljail
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 7e5cdf1..b7747d8 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -469,6 +469,7 @@ MAN= aac.4 \
urio.4 \
${_urtw.4} \
usb.4 \
+ usb_quirk.4 \
uslcom.4 \
utopia.4 \
uvisor.4 \
diff --git a/share/man/man4/ada.4 b/share/man/man4/ada.4
index 08acd44..87adac9 100644
--- a/share/man/man4/ada.4
+++ b/share/man/man4/ada.4
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 19, 2009
+.Dd October 24, 2010
.Dt ADA 4
.Os
.Sh NAME
diff --git a/share/man/man4/aibs.4 b/share/man/man4/aibs.4
index 61e34ca..b865ec8 100644
--- a/share/man/man4/aibs.4
+++ b/share/man/man4/aibs.4
@@ -24,18 +24,16 @@
.Nd "ASUSTeK AI Booster ACPI ATK0110 voltage, temperature and fan sensor"
.Sh SYNOPSIS
To compile this driver into the kernel,
-place the following lines in your
+place the following line in your
kernel configuration file:
.Bd -ragged -offset indent
-.Cd "device acpi"
.Cd "device aibs"
.Ed
.Pp
Alternatively, to load the driver as a
-module at boot time, place the following lines in
+module at boot time, place the following line in
.Xr loader.conf 5 :
.Bd -literal -offset indent
-acpi_load="YES"
aibs_load="YES"
.Ed
.Sh DESCRIPTION
diff --git a/share/man/man4/bge.4 b/share/man/man4/bge.4
index e3509c7..086045f 100644
--- a/share/man/man4/bge.4
+++ b/share/man/man4/bge.4
@@ -31,12 +31,12 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 21, 2010
+.Dd November 7, 2010
.Dt BGE 4
.Os
.Sh NAME
.Nm bge
-.Nd "Broadcom BCM570x/5714/5721/5722/5750/5751/5752/5761/5784/5789/57780 PCI Gigabit Ethernet adapter driver"
+.Nd "Broadcom BCM57xx/BCM590x Gigabit/Fast Ethernet driver"
.Sh SYNOPSIS
To compile this driver into the kernel,
place the following lines in your
@@ -56,8 +56,8 @@ if_bge_load="YES"
The
.Nm
driver provides support for various NICs based on the Broadcom BCM570x,
-5714, 5721, 5722, 5750, 5751, 5752, 5761, 5784, 5789 and 57780 families
-of Gigabit Ethernet controller chips.
+571x, 572x, 575x, 576x, 578x, 5776x and 5778x Gigabit Ethernet controller
+chips and the 590x and 5779x Fast Ethernet controller chips.
.Pp
All of these NICs are capable of 10, 100 and 1000Mbps speeds over CAT5
copper cable, except for the SysKonnect SK-9D41 which supports only
@@ -82,7 +82,7 @@ copper gigabit transceivers,
which support autonegotiation of 10, 100 and 1000Mbps modes in
full or half duplex.
.Pp
-The BCM5700, BCM5701, BCM5702, BCM5703 and BCM5704 also support
+The BCM5700, BCM5701, BCM5702, BCM5703, BCM5704 and BCM5717 also support
jumbo frames, which can be configured
via the interface MTU setting.
Selecting an MTU larger than 1500 bytes with the
diff --git a/share/man/man4/u3g.4 b/share/man/man4/u3g.4
index eb192f9..d012353 100644
--- a/share/man/man4/u3g.4
+++ b/share/man/man4/u3g.4
@@ -85,26 +85,19 @@ In some of these devices a mass storage device supported by the
.Xr umass 4
driver is present which contains Windows and Mac OS X drivers.
The device starts up in disk mode (TruInstall, ZeroCD, etc.) and requires
-additional commands to switch it to modem mode.
+additional commands to switch it to modem mode. If your device is not
+switching automatically, please try to add quirks. See
+.Xr usbconfig 5
+and
+.Xr usb_quirk 4 .
.Pp
-The
-.Xr u3gstub 4
-device will attach temporarily to a 3G device with a mass storage device and
-force it to switch to modem mode.
-The attach and detach of
-.Xr u3gstub
-and any driver disk device present on the 3G device is hidden, unless the
-machine was booted in verbose mode (see
-.Xr boot 8 ) .
-To temporarily unhide the device, set
-.Va debug.bootverbose
-to 1 using
-.Xr sysctl 8
-and replug the device.
.Sh SEE ALSO
.Xr tty 4 ,
.Xr ucom 4 ,
-.Xr usb 4
+.XR u3g 4 ,
+.Xr usb 4 ,
+.Xr usb_quirk 4 ,
+.Xr usbconfig 5
.Sh HISTORY
The
.Nm
diff --git a/share/man/man4/usb_quirk.4 b/share/man/man4/usb_quirk.4
new file mode 100644
index 0000000..33b224a
--- /dev/null
+++ b/share/man/man4/usb_quirk.4
@@ -0,0 +1,196 @@
+.\"
+.\" Copyright (c) 2010 AnyWi Technologies
+.\" All rights reserved.
+.\"
+.\" 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd November 9, 2010
+.Dt USB_QUIRK 4
+.Os
+.Sh NAME
+.Nm usb_quirk
+.Nd USB quirks module
+.Sh SYNOPSIS
+To compile this module into the kernel,
+place the following line in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device ucom"
+.Ed
+.Pp
+Alternatively, to load the module at boot
+time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+usb_quirk_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+module provides support for dynamically adding and removing quirks for
+USB devices with
+.Xr usbconfig 5 .
+.Sh General quirks:
+.Bl -tag -width Ds
+.It UQ_AUDIO_SWAP_LR
+swap left and right channels
+.It UQ_AU_INP_ASYNC
+input is async despite claim of adaptive
+.It UQ_AU_NO_FRAC
+don't adjust for fractional samples
+.It UQ_AU_NO_XU
+audio device has broken extension unit
+.It UQ_BAD_ADC
+bad audio spec version number
+.It UQ_BAD_AUDIO
+device claims audio class, but isn't
+.It UQ_BROKEN_BIDIR
+printer has broken bidir mode
+.It UQ_BUS_POWERED
+device is bus powered, despite claim
+.It UQ_HID_IGNORE
+device should be ignored by hid class
+.It UQ_KBD_IGNORE
+device should be ignored by kbd class
+.It UQ_KBD_BOOTPROTO
+device should set the boot protocol
+.It UQ_MS_BAD_CLASS
+doesn't identify properly
+.It UQ_MS_LEADING_BYTE
+mouse sends an unknown leading byte
+.It UQ_MS_REVZ
+mouse has Z-axis reversed
+.It UQ_NO_STRINGS
+string descriptors are broken
+.It UQ_OPEN_CLEARSTALL
+device needs clear endpoint stall
+.It UQ_POWER_CLAIM
+hub lies about power status
+.It UQ_SPUR_BUT_UP
+spurious mouse button up events
+.It UQ_SWAP_UNICODE
+has some Unicode strings swapped
+.It UQ_CFG_INDEX_1
+select configuration index 1 by default
+.It UQ_CFG_INDEX_2
+select configuration index 2 by default
+.It UQ_CFG_INDEX_3
+select configuration index 3 by default
+.It UQ_CFG_INDEX_4
+select configuration index 4 by default
+.It UQ_CFG_INDEX_0
+select configuration index 0 by default
+.It UQ_ASSUME_CM_OVER_DATA
+assume cm over data feature
+.El
+.Sh USB Mass Storage Quirks
+.Bl -tag -width Ds
+.It UQ_MSC_NO_TEST_UNIT_READY
+send start/stop instead of TUR
+.It UQ_MSC_NO_RS_CLEAR_UA
+does not reset Unit Att.
+.It UQ_MSC_NO_START_STOP
+does not support start/stop
+.It UQ_MSC_NO_GETMAXLUN
+does not support get max LUN
+.It UQ_MSC_NO_INQUIRY
+fake generic inq response
+.It UQ_MSC_NO_INQUIRY_EVPD
+does not support inq EVPD
+.It UQ_MSC_NO_SYNC_CACHE
+does not support sync cache
+.It UQ_MSC_SHUTTLE_INIT
+requires Shuttle init sequence
+.It UQ_MSC_ALT_IFACE_1
+switch to alternate interface 1
+.It UQ_MSC_FLOPPY_SPEED
+does floppy speeds (20kb/s)
+.It UQ_MSC_IGNORE_RESIDUE
+gets residue wrong
+.It UQ_MSC_WRONG_CSWSIG
+uses wrong CSW signature
+.It UQ_MSC_RBC_PAD_TO_12
+pad RBC requests to 12 bytes
+.It UQ_MSC_READ_CAP_OFFBY1
+reports sector count, not max sec.
+.It UQ_MSC_FORCE_SHORT_INQ
+does not support full inq.
+.It UQ_MSC_FORCE_WIRE_BBB
+force BBB wire protocol
+.It UQ_MSC_FORCE_WIRE_CBI
+force CBI wire protocol
+.It UQ_MSC_FORCE_WIRE_CBI_I
+force CBI with int. wire protocol
+.It UQ_MSC_FORCE_PROTO_SCSI
+force SCSI command protocol
+.It UQ_MSC_FORCE_PROTO_ATAPI
+force ATAPI command protocol
+.It UQ_MSC_FORCE_PROTO_UFI
+force UFI command protocol
+.It UQ_MSC_FORCE_PROTO_RBC
+force RBC command protocol
+.El
+.Sh Mass Storage Change (u3g) quirks:
+.Bl -tag -width Ds
+.It UQ_MSC_EJECT_HUAWEI
+ejects after Huawei USB command
+.It UQ_MSC_EJECT_SIERRA
+ejects after Sierra USB command
+.It UQ_MSC_EJECT_SCSIEJECT
+ejects after SCSI eject command
+0x1b0000000200
+.It UQ_MSC_EJECT_REZERO
+ejects after SCSI rezero command
+0x010000000000
+.It UQ_MSC_EJECT_ZTESTOR
+ejects after ZTE SCSI command
+0x850101011801010101010000
+.It UQ_MSC_EJECT_CMOTECH
+ejects after C-motech SCSI command
+0xff52444556434847
+.It UQ_MSC_EJECT_WAIT
+wait for the device to eject
+.It UQ_MSC_EJECT_SAEL_M460
+ejects after Sael USB commands
+.It UQ_MSC_EJECT_HUAWEISCSI
+ejects after Huawei SCSI command
+0x11060000000000000000000000000000
+.It UQ_MSC_EJECT_TCT
+ejects after TCT SCSI command
+0x06f504025270
+.El
+See
+.Pa /sys/dev/usb/quirk/usb_quirk.h
+for the complete list of supported quirks.
+.Sh EXAMPLES
+After attaching a
+.Nm u3g
+device which appears as a USB device on
+.Pa ugen0.3 :
+.Bd -literal -offset indent
+usbconfig -d ugen0.3 add_quirk UQ_MSC_EJECT_WAIT
+.Ed
+.Sh SEE ALSO
+.Xr usb_quirk 4 ,
+.Xr usbconfig 5
+.Sh HISTORY
+The
+.Nm
+module appeared in
+.Fx 8.0 ,
+and was written by
+.An Hans Petter Selasky Aq hselasky@FreeBSD.org .
+This manual page was written by
+.An Nick Hibma Aq n_hibma@FreeBSD.org .
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index e6a490a..ecb1dff 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1212,6 +1212,7 @@ MLINKS+=sysctl_ctx_init.9 sysctl_ctx_entry_add.9 \
sysctl_ctx_init.9 sysctl_ctx_entry_find.9 \
sysctl_ctx_init.9 sysctl_ctx_free.9
MLINKS+=taskqueue.9 TASK_INIT.9 \
+ taskqueue.9 taskqueue_cancel.9 \
taskqueue.9 taskqueue_create.9 \
taskqueue.9 taskqueue_create_fast.9 \
taskqueue.9 TASKQUEUE_DECLARE.9 \
diff --git a/share/man/man9/taskqueue.9 b/share/man/man9/taskqueue.9
index d5e096a..168ca70 100644
--- a/share/man/man9/taskqueue.9
+++ b/share/man/man9/taskqueue.9
@@ -63,6 +63,8 @@ struct task {
.Fn taskqueue_enqueue "struct taskqueue *queue" "struct task *task"
.Ft int
.Fn taskqueue_enqueue_fast "struct taskqueue *queue" "struct task *task"
+.Ft int
+.Fn taskqueue_cancel "struct taskqueue *queue" "struct task *task" "u_int *pendp"
.Ft void
.Fn taskqueue_drain "struct taskqueue *queue" "struct task *task"
.Ft int
@@ -162,6 +164,31 @@ is called on the task pointer passed to
.Fn taskqueue_enqueue .
.Pp
The
+.Fn taskqueue_cancel
+function is used to cancel a task.
+The
+.Va ta_pending
+count is cleared, and the old value returned in the reference
+parameter
+.Fa pendp ,
+if it is non- Dv NULL .
+If the task is currently running,
+.Dv EBUSY
+is returned, otherwise 0.
+To implement a blocking
+.Fn taskqueue_cancel
+that waits for a running task to finish, it could look like:
+.Bd -literal -offset indent
+while (taskqueue_cancel(tq, task, NULL) != 0)
+ taskqueue_drain(tq, task);
+.Ed
+.Pp
+Note that, as with
+.Fn taskqueue_drain ,
+the caller is responsible for ensuring that the task is not re-enqueued
+after being canceled.
+.Pp
+The
.Fn taskqueue_drain
function is used to wait for the task to finish.
There is no guarantee that the task will not be
diff --git a/share/misc/committers-src.dot b/share/misc/committers-src.dot
index d7eb091..b09ea7c 100644
--- a/share/misc/committers-src.dot
+++ b/share/misc/committers-src.dot
@@ -211,6 +211,7 @@ wilko [label="Wilko Bulte\nwilko@FreeBSD.org\n2000/01/13"]
wsalamon [label="Wayne Salamon\nwsalamon@FreeBSD.org\n2005/06/25"]
yar [label="Yar Tikhiy\nyar@FreeBSD.org\n2001/03/25"]
yongari [label="Pyun YongHyeon\nyongari@FreeBSD.org\n2004/08/01"]
+zack [label="Zack Kirsch\nzack@FreeBSD.org\n2010/11/05"]
zec [label="Marko Zec\nzec@FreeBSD.org\n2008/06/22"]
# Pseudo target representing rev 1.1 of commit.allow
@@ -503,5 +504,6 @@ wes -> scf
wollman -> gad
zml -> mdf
+zml -> zack
}
diff --git a/share/mk/bsd.cpu.mk b/share/mk/bsd.cpu.mk
index 93d8bc4..5795e95 100644
--- a/share/mk/bsd.cpu.mk
+++ b/share/mk/bsd.cpu.mk
@@ -114,7 +114,7 @@ _CPUCFLAGS = -march=armv5te -D__XSCALE__
. else
_CPUCFLAGS = -mcpu=${CPUTYPE}
. endif
-. elif ${MACHINE_ARCH} == "powerpc"
+. elif ${MACHINE_CPUARCH} == "powerpc"
. if ${CPUTYPE} == "e500"
MACHINE_CPU = booke
_CPUCFLAGS = -Wa,-me500 -msoft-float
@@ -196,12 +196,6 @@ MACHINE_CPU = itanium
. endif
.endif
-.if ${MACHINE_CPUARCH} == "arm" && defined(TARGET_BIG_ENDIAN)
-CFLAGS += -mbig-endian
-LDFLAGS += -mbig-endian
-LD += -EB
-.endif
-
.if ${MACHINE_CPUARCH} == "mips"
CFLAGS += -G0
.endif
diff --git a/share/mk/bsd.endian.mk b/share/mk/bsd.endian.mk
index 8ef72e5..2bc75b0 100644
--- a/share/mk/bsd.endian.mk
+++ b/share/mk/bsd.endian.mk
@@ -3,13 +3,13 @@
.if ${MACHINE_ARCH} == "amd64" || \
${MACHINE_ARCH} == "i386" || \
${MACHINE_ARCH} == "ia64" || \
- (${MACHINE_ARCH} == "arm" && !defined(TARGET_BIG_ENDIAN)) || \
- (${MACHINE_ARCH} == "mips" && !defined(TARGET_BIG_ENDIAN))
+ ${MACHINE_ARCH} == "arm" || \
+ ${MACHINE_ARCH} == "mipsel"
TARGET_ENDIANNESS= 1234
.elif ${MACHINE_ARCH} == "powerpc" || \
${MACHINE_ARCH} == "powerpc64" || \
${MACHINE_ARCH} == "sparc64" || \
- ${MACHINE_ARCH} == "arm" || \
- ${MACHINE_ARCH} == "mips"
+ ${MACHINE_ARCH} == "armeb" || \
+ ${MACHINE_ARCH} == "mipseb"
TARGET_ENDIANNESS= 4321
.endif
diff --git a/sys/amd64/acpica/acpi_machdep.c b/sys/amd64/acpica/acpi_machdep.c
index 8c66696..e33e613 100644
--- a/sys/amd64/acpica/acpi_machdep.c
+++ b/sys/amd64/acpica/acpi_machdep.c
@@ -44,24 +44,6 @@ __FBSDID("$FreeBSD$");
#include <machine/nexusvar.h>
-/*
- * APM driver emulation
- */
-
-#include <sys/condvar.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/malloc.h>
-#include <sys/poll.h>
-#include <sys/uio.h>
-
-#include <dev/acpica/acpiio.h>
-
-#include <machine/apm_bios.h>
-#include <i386/include/pc/bios.h>
-
-#include <i386/bios/apm.h>
-
SYSCTL_DECL(_debug_acpi);
int acpi_resume_beep;
@@ -73,445 +55,15 @@ int acpi_reset_video;
TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video);
static int intr_model = ACPI_INTR_PIC;
-static int apm_active;
-static struct clonedevs *apm_clones;
-
-MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation");
-
-static d_open_t apmopen;
-static d_close_t apmclose;
-static d_write_t apmwrite;
-static d_ioctl_t apmioctl;
-static d_poll_t apmpoll;
-static d_kqfilter_t apmkqfilter;
-static void apmreadfiltdetach(struct knote *kn);
-static int apmreadfilt(struct knote *kn, long hint);
-static struct filterops apm_readfiltops = {
- .f_isfd = 1,
- .f_detach = apmreadfiltdetach,
- .f_event = apmreadfilt,
-};
-
-static struct cdevsw apm_cdevsw = {
- .d_version = D_VERSION,
- .d_flags = D_TRACKCLOSE | D_NEEDMINOR,
- .d_open = apmopen,
- .d_close = apmclose,
- .d_write = apmwrite,
- .d_ioctl = apmioctl,
- .d_poll = apmpoll,
- .d_name = "apm",
- .d_kqfilter = apmkqfilter
-};
-
-static int
-acpi_capm_convert_battstate(struct acpi_battinfo *battp)
-{
- int state;
-
- state = APM_UNKNOWN;
-
- if (battp->state & ACPI_BATT_STAT_DISCHARG) {
- if (battp->cap >= 50)
- state = 0; /* high */
- else
- state = 1; /* low */
- }
- if (battp->state & ACPI_BATT_STAT_CRITICAL)
- state = 2; /* critical */
- if (battp->state & ACPI_BATT_STAT_CHARGING)
- state = 3; /* charging */
-
- /* If still unknown, determine it based on the battery capacity. */
- if (state == APM_UNKNOWN) {
- if (battp->cap >= 50)
- state = 0; /* high */
- else
- state = 1; /* low */
- }
-
- return (state);
-}
-
-static int
-acpi_capm_convert_battflags(struct acpi_battinfo *battp)
-{
- int flags;
-
- flags = 0;
-
- if (battp->cap >= 50)
- flags |= APM_BATT_HIGH;
- else {
- if (battp->state & ACPI_BATT_STAT_CRITICAL)
- flags |= APM_BATT_CRITICAL;
- else
- flags |= APM_BATT_LOW;
- }
- if (battp->state & ACPI_BATT_STAT_CHARGING)
- flags |= APM_BATT_CHARGING;
- if (battp->state == ACPI_BATT_STAT_NOT_PRESENT)
- flags = APM_BATT_NOT_PRESENT;
-
- return (flags);
-}
-
-static int
-acpi_capm_get_info(apm_info_t aip)
-{
- int acline;
- struct acpi_battinfo batt;
-
- aip->ai_infoversion = 1;
- aip->ai_major = 1;
- aip->ai_minor = 2;
- aip->ai_status = apm_active;
- aip->ai_capabilities= 0xff00; /* unknown */
-
- if (acpi_acad_get_acline(&acline))
- aip->ai_acline = APM_UNKNOWN; /* unknown */
- else
- aip->ai_acline = acline; /* on/off */
-
- if (acpi_battery_get_battinfo(NULL, &batt) != 0) {
- aip->ai_batt_stat = APM_UNKNOWN;
- aip->ai_batt_life = APM_UNKNOWN;
- aip->ai_batt_time = -1; /* unknown */
- aip->ai_batteries = ~0U; /* unknown */
- } else {
- aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
- aip->ai_batt_life = batt.cap;
- aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
- aip->ai_batteries = acpi_battery_get_units();
- }
-
- return (0);
-}
-
-static int
-acpi_capm_get_pwstatus(apm_pwstatus_t app)
-{
- device_t dev;
- int acline, unit, error;
- struct acpi_battinfo batt;
-
- if (app->ap_device != PMDV_ALLDEV &&
- (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
- return (1);
-
- if (app->ap_device == PMDV_ALLDEV)
- error = acpi_battery_get_battinfo(NULL, &batt);
- else {
- unit = app->ap_device - PMDV_BATT0;
- dev = devclass_get_device(devclass_find("battery"), unit);
- if (dev != NULL)
- error = acpi_battery_get_battinfo(dev, &batt);
- else
- error = ENXIO;
- }
- if (error)
- return (1);
-
- app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
- app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
- app->ap_batt_life = batt.cap;
- app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
-
- if (acpi_acad_get_acline(&acline))
- app->ap_acline = APM_UNKNOWN;
- else
- app->ap_acline = acline; /* on/off */
-
- return (0);
-}
-
-/* Create single-use devices for /dev/apm and /dev/apmctl. */
-static void
-apm_clone(void *arg, struct ucred *cred, char *name, int namelen,
- struct cdev **dev)
-{
- int ctl_dev, unit;
-
- if (*dev != NULL)
- return;
- if (strcmp(name, "apmctl") == 0)
- ctl_dev = TRUE;
- else if (strcmp(name, "apm") == 0)
- ctl_dev = FALSE;
- else
- return;
-
- /* Always create a new device and unit number. */
- unit = -1;
- if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) {
- if (ctl_dev) {
- *dev = make_dev(&apm_cdevsw, unit,
- UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit);
- } else {
- *dev = make_dev(&apm_cdevsw, unit,
- UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit);
- }
- if (*dev != NULL) {
- dev_ref(*dev);
- (*dev)->si_flags |= SI_CHEAPCLONE;
- }
- }
-}
-
-/* Create a struct for tracking per-device suspend notification. */
-static struct apm_clone_data *
-apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc)
-{
- struct apm_clone_data *clone;
-
- clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK);
- clone->cdev = dev;
- clone->acpi_sc = acpi_sc;
- clone->notify_status = APM_EV_NONE;
- bzero(&clone->sel_read, sizeof(clone->sel_read));
- knlist_init_mtx(&clone->sel_read.si_note, &acpi_mutex);
-
- /*
- * The acpi device is always managed by devd(8) and is considered
- * writable (i.e., ack is required to allow suspend to proceed.)
- */
- if (strcmp("acpi", devtoname(dev)) == 0)
- clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE;
- else
- clone->flags = ACPI_EVF_NONE;
-
- ACPI_LOCK(acpi);
- STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries);
- ACPI_UNLOCK(acpi);
- return (clone);
-}
-
-static int
-apmopen(struct cdev *dev, int flag, int fmt, struct thread *td)
-{
- struct acpi_softc *acpi_sc;
- struct apm_clone_data *clone;
-
- acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
- clone = apm_create_clone(dev, acpi_sc);
- dev->si_drv1 = clone;
-
- /* If the device is opened for write, record that. */
- if ((flag & FWRITE) != 0)
- clone->flags |= ACPI_EVF_WRITE;
-
- return (0);
-}
-
-static int
-apmclose(struct cdev *dev, int flag, int fmt, struct thread *td)
-{
- struct apm_clone_data *clone;
- struct acpi_softc *acpi_sc;
-
- clone = dev->si_drv1;
- acpi_sc = clone->acpi_sc;
-
- /* We are about to lose a reference so check if suspend should occur */
- if (acpi_sc->acpi_next_sstate != 0 &&
- clone->notify_status != APM_EV_ACKED)
- acpi_AckSleepState(clone, 0);
-
- /* Remove this clone's data from the list and free it. */
- ACPI_LOCK(acpi);
- STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries);
- knlist_destroy(&clone->sel_read.si_note);
- ACPI_UNLOCK(acpi);
- free(clone, M_APMDEV);
- destroy_dev_sched(dev);
- return (0);
-}
-
-static int
-apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- int error;
- struct apm_clone_data *clone;
- struct acpi_softc *acpi_sc;
- struct apm_info info;
- struct apm_event_info *ev_info;
- apm_info_old_t aiop;
-
- error = 0;
- clone = dev->si_drv1;
- acpi_sc = clone->acpi_sc;
-
- switch (cmd) {
- case APMIO_SUSPEND:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- if (acpi_sc->acpi_next_sstate == 0) {
- if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) {
- error = acpi_ReqSleepState(acpi_sc,
- acpi_sc->acpi_suspend_sx);
- } else {
- printf(
- "power off via apm suspend not supported\n");
- error = ENXIO;
- }
- } else
- error = acpi_AckSleepState(clone, 0);
- break;
- case APMIO_STANDBY:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- if (acpi_sc->acpi_next_sstate == 0) {
- if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) {
- error = acpi_ReqSleepState(acpi_sc,
- acpi_sc->acpi_standby_sx);
- } else {
- printf(
- "power off via apm standby not supported\n");
- error = ENXIO;
- }
- } else
- error = acpi_AckSleepState(clone, 0);
- break;
- case APMIO_NEXTEVENT:
- printf("apm nextevent start\n");
- ACPI_LOCK(acpi);
- if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status ==
- APM_EV_NONE) {
- ev_info = (struct apm_event_info *)addr;
- if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3)
- ev_info->type = PMEV_STANDBYREQ;
- else
- ev_info->type = PMEV_SUSPENDREQ;
- ev_info->index = 0;
- clone->notify_status = APM_EV_NOTIFIED;
- printf("apm event returning %d\n", ev_info->type);
- } else
- error = EAGAIN;
- ACPI_UNLOCK(acpi);
- break;
- case APMIO_GETINFO_OLD:
- if (acpi_capm_get_info(&info))
- error = ENXIO;
- aiop = (apm_info_old_t)addr;
- aiop->ai_major = info.ai_major;
- aiop->ai_minor = info.ai_minor;
- aiop->ai_acline = info.ai_acline;
- aiop->ai_batt_stat = info.ai_batt_stat;
- aiop->ai_batt_life = info.ai_batt_life;
- aiop->ai_status = info.ai_status;
- break;
- case APMIO_GETINFO:
- if (acpi_capm_get_info((apm_info_t)addr))
- error = ENXIO;
- break;
- case APMIO_GETPWSTATUS:
- if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
- error = ENXIO;
- break;
- case APMIO_ENABLE:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- apm_active = 1;
- break;
- case APMIO_DISABLE:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- apm_active = 0;
- break;
- case APMIO_HALTCPU:
- break;
- case APMIO_NOTHALTCPU:
- break;
- case APMIO_DISPLAY:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- break;
- case APMIO_BIOS:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- bzero(addr, sizeof(struct apm_bios_arg));
- break;
- default:
- error = EINVAL;
- break;
- }
-
- return (error);
-}
-
-static int
-apmwrite(struct cdev *dev, struct uio *uio, int ioflag)
-{
- return (uio->uio_resid);
-}
-
-static int
-apmpoll(struct cdev *dev, int events, struct thread *td)
-{
- struct apm_clone_data *clone;
- int revents;
-
- revents = 0;
- ACPI_LOCK(acpi);
- clone = dev->si_drv1;
- if (clone->acpi_sc->acpi_next_sstate)
- revents |= events & (POLLIN | POLLRDNORM);
- else
- selrecord(td, &clone->sel_read);
- ACPI_UNLOCK(acpi);
- return (revents);
-}
-
-static int
-apmkqfilter(struct cdev *dev, struct knote *kn)
-{
- struct apm_clone_data *clone;
-
- ACPI_LOCK(acpi);
- clone = dev->si_drv1;
- kn->kn_hook = clone;
- kn->kn_fop = &apm_readfiltops;
- knlist_add(&clone->sel_read.si_note, kn, 0);
- ACPI_UNLOCK(acpi);
- return (0);
-}
-
-static void
-apmreadfiltdetach(struct knote *kn)
-{
- struct apm_clone_data *clone;
-
- ACPI_LOCK(acpi);
- clone = kn->kn_hook;
- knlist_remove(&clone->sel_read.si_note, kn, 0);
- ACPI_UNLOCK(acpi);
-}
-
-static int
-apmreadfilt(struct knote *kn, long hint)
-{
- struct apm_clone_data *clone;
- int sleeping;
-
- ACPI_LOCK(acpi);
- clone = kn->kn_hook;
- sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0;
- ACPI_UNLOCK(acpi);
- return (sleeping);
-}
int
acpi_machdep_init(device_t dev)
{
- struct acpi_softc *sc;
+ struct acpi_softc *sc;
- sc = devclass_get_softc(devclass_find("acpi"), 0);
+ sc = device_get_softc(dev);
- /* Create a clone for /dev/acpi also. */
- STAILQ_INIT(&sc->apm_cdevs);
- sc->acpi_clone = apm_create_clone(sc->acpi_dev_t, sc);
- clone_setup(&apm_clones);
- EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000);
+ acpi_apm_init(sc);
if (intr_model != ACPI_INTR_PIC)
acpi_SetIntrModel(intr_model);
@@ -534,12 +86,14 @@ acpi_SetDefaultIntrModel(int model)
int
acpi_machdep_quirks(int *quirks)
{
+
return (0);
}
void
acpi_cpu_c1()
{
+
__asm __volatile("sti; hlt");
}
diff --git a/sys/amd64/acpica/madt.c b/sys/amd64/acpica/madt.c
deleted file mode 100644
index 84bc831..0000000
--- a/sys/amd64/acpica/madt.c
+++ /dev/null
@@ -1,573 +0,0 @@
-/*-
- * Copyright (c) 2003 John Baldwin <jhb@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. 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 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/smp.h>
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <x86/apicreg.h>
-#include <machine/intr_machdep.h>
-#include <machine/apicvar.h>
-
-#include <contrib/dev/acpica/include/acpi.h>
-#include <contrib/dev/acpica/include/actables.h>
-
-#include <dev/acpica/acpivar.h>
-#include <dev/pci/pcivar.h>
-
-/* These two arrays are indexed by APIC IDs. */
-struct ioapic_info {
- void *io_apic;
- UINT32 io_vector;
-} ioapics[MAX_APIC_ID + 1];
-
-struct lapic_info {
- u_int la_enabled:1;
- u_int la_acpi_id:8;
-} lapics[MAX_APIC_ID + 1];
-
-static int madt_found_sci_override;
-static ACPI_TABLE_MADT *madt;
-static vm_paddr_t madt_physaddr;
-static vm_offset_t madt_length;
-
-MALLOC_DEFINE(M_MADT, "madt_table", "ACPI MADT Table Items");
-
-static enum intr_polarity interrupt_polarity(UINT16 IntiFlags, UINT8 Source);
-static enum intr_trigger interrupt_trigger(UINT16 IntiFlags, UINT8 Source);
-static int madt_find_cpu(u_int acpi_id, u_int *apic_id);
-static int madt_find_interrupt(int intr, void **apic, u_int *pin);
-static void madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg);
-static void madt_parse_interrupt_override(
- ACPI_MADT_INTERRUPT_OVERRIDE *intr);
-static void madt_parse_ints(ACPI_SUBTABLE_HEADER *entry,
- void *arg __unused);
-static void madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi);
-static void madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi);
-static int madt_probe(void);
-static int madt_probe_cpus(void);
-static void madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry,
- void *arg __unused);
-static void madt_register(void *dummy);
-static int madt_setup_local(void);
-static int madt_setup_io(void);
-static void madt_walk_table(acpi_subtable_handler *handler, void *arg);
-
-static struct apic_enumerator madt_enumerator = {
- "MADT",
- madt_probe,
- madt_probe_cpus,
- madt_setup_local,
- madt_setup_io
-};
-
-/*
- * Look for an ACPI Multiple APIC Description Table ("APIC")
- */
-static int
-madt_probe(void)
-{
-
- madt_physaddr = acpi_find_table(ACPI_SIG_MADT);
- if (madt_physaddr == 0)
- return (ENXIO);
- return (0);
-}
-
-/*
- * Run through the MP table enumerating CPUs.
- */
-static int
-madt_probe_cpus(void)
-{
-
- madt = acpi_map_table(madt_physaddr, ACPI_SIG_MADT);
- madt_length = madt->Header.Length;
- KASSERT(madt != NULL, ("Unable to re-map MADT"));
- madt_walk_table(madt_probe_cpus_handler, NULL);
- acpi_unmap_table(madt);
- madt = NULL;
- return (0);
-}
-
-/*
- * Initialize the local APIC on the BSP.
- */
-static int
-madt_setup_local(void)
-{
-
- madt = pmap_mapbios(madt_physaddr, madt_length);
- lapic_init(madt->Address);
- printf("ACPI APIC Table: <%.*s %.*s>\n",
- (int)sizeof(madt->Header.OemId), madt->Header.OemId,
- (int)sizeof(madt->Header.OemTableId), madt->Header.OemTableId);
-
- /*
- * We ignore 64-bit local APIC override entries. Should we
- * perhaps emit a warning here if we find one?
- */
- return (0);
-}
-
-/*
- * Enumerate I/O APICs and setup interrupt sources.
- */
-static int
-madt_setup_io(void)
-{
- void *ioapic;
- u_int pin;
- int i;
-
- /* Try to initialize ACPI so that we can access the FADT. */
- i = acpi_Startup();
- if (ACPI_FAILURE(i)) {
- printf("MADT: ACPI Startup failed with %s\n",
- AcpiFormatException(i));
- printf("Try disabling either ACPI or apic support.\n");
- panic("Using MADT but ACPI doesn't work");
- }
-
- /* First, we run through adding I/O APIC's. */
- madt_walk_table(madt_parse_apics, NULL);
-
- /* Second, we run through the table tweaking interrupt sources. */
- madt_walk_table(madt_parse_ints, NULL);
-
- /*
- * If there was not an explicit override entry for the SCI,
- * force it to use level trigger and active-low polarity.
- */
- if (!madt_found_sci_override) {
- if (madt_find_interrupt(AcpiGbl_FADT.SciInterrupt, &ioapic,
- &pin) != 0)
- printf("MADT: Could not find APIC for SCI IRQ %u\n",
- AcpiGbl_FADT.SciInterrupt);
- else {
- printf(
- "MADT: Forcing active-low polarity and level trigger for SCI\n");
- ioapic_set_polarity(ioapic, pin, INTR_POLARITY_LOW);
- ioapic_set_triggermode(ioapic, pin, INTR_TRIGGER_LEVEL);
- }
- }
-
- /* Third, we register all the I/O APIC's. */
- for (i = 0; i <= MAX_APIC_ID; i++)
- if (ioapics[i].io_apic != NULL)
- ioapic_register(ioapics[i].io_apic);
-
- /* Finally, we throw the switch to enable the I/O APIC's. */
- acpi_SetDefaultIntrModel(ACPI_INTR_APIC);
-
- return (0);
-}
-
-static void
-madt_register(void *dummy __unused)
-{
-
- apic_register_enumerator(&madt_enumerator);
-}
-SYSINIT(madt_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST,
- madt_register, NULL);
-
-/*
- * Call the handler routine for each entry in the MADT table.
- */
-static void
-madt_walk_table(acpi_subtable_handler *handler, void *arg)
-{
-
- acpi_walk_subtables(madt + 1, (char *)madt + madt->Header.Length,
- handler, arg);
-}
-
-static void
-madt_probe_cpus_handler(ACPI_SUBTABLE_HEADER *entry, void *arg)
-{
- ACPI_MADT_LOCAL_APIC *proc;
- struct lapic_info *la;
-
- switch (entry->Type) {
- case ACPI_MADT_TYPE_LOCAL_APIC:
- /*
- * The MADT does not include a BSP flag, so we have to
- * let the MP code figure out which CPU is the BSP on
- * its own.
- */
- proc = (ACPI_MADT_LOCAL_APIC *)entry;
- if (bootverbose)
- printf("MADT: Found CPU APIC ID %u ACPI ID %u: %s\n",
- proc->Id, proc->ProcessorId,
- (proc->LapicFlags & ACPI_MADT_ENABLED) ?
- "enabled" : "disabled");
- if (!(proc->LapicFlags & ACPI_MADT_ENABLED))
- break;
- if (proc->Id > MAX_APIC_ID)
- panic("%s: CPU ID %u too high", __func__, proc->Id);
- la = &lapics[proc->Id];
- KASSERT(la->la_enabled == 0,
- ("Duplicate local APIC ID %u", proc->Id));
- la->la_enabled = 1;
- la->la_acpi_id = proc->ProcessorId;
- lapic_create(proc->Id, 0);
- break;
- }
-}
-
-
-/*
- * Add an I/O APIC from an entry in the table.
- */
-static void
-madt_parse_apics(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
-{
- ACPI_MADT_IO_APIC *apic;
-
- switch (entry->Type) {
- case ACPI_MADT_TYPE_IO_APIC:
- apic = (ACPI_MADT_IO_APIC *)entry;
- if (bootverbose)
- printf(
- "MADT: Found IO APIC ID %u, Interrupt %u at %p\n",
- apic->Id, apic->GlobalIrqBase,
- (void *)(uintptr_t)apic->Address);
- if (apic->Id > MAX_APIC_ID)
- panic("%s: I/O APIC ID %u too high", __func__,
- apic->Id);
- if (ioapics[apic->Id].io_apic != NULL)
- panic("%s: Double APIC ID %u", __func__, apic->Id);
- if (apic->GlobalIrqBase >= FIRST_MSI_INT) {
- printf("MADT: Ignoring bogus I/O APIC ID %u", apic->Id);
- break;
- }
- ioapics[apic->Id].io_apic = ioapic_create(apic->Address,
- apic->Id, apic->GlobalIrqBase);
- ioapics[apic->Id].io_vector = apic->GlobalIrqBase;
- break;
- default:
- break;
- }
-}
-
-/*
- * Determine properties of an interrupt source. Note that for ACPI these
- * functions are only used for ISA interrupts, so we assume ISA bus values
- * (Active Hi, Edge Triggered) for conforming values except for the ACPI
- * SCI for which we use Active Lo, Level Triggered.
- */
-static enum intr_polarity
-interrupt_polarity(UINT16 IntiFlags, UINT8 Source)
-{
-
- switch (IntiFlags & ACPI_MADT_POLARITY_MASK) {
- case ACPI_MADT_POLARITY_CONFORMS:
- if (Source == AcpiGbl_FADT.SciInterrupt)
- return (INTR_POLARITY_LOW);
- else
- return (INTR_POLARITY_HIGH);
- case ACPI_MADT_POLARITY_ACTIVE_HIGH:
- return (INTR_POLARITY_HIGH);
- case ACPI_MADT_POLARITY_ACTIVE_LOW:
- return (INTR_POLARITY_LOW);
- default:
- panic("Bogus Interrupt Polarity");
- }
-}
-
-static enum intr_trigger
-interrupt_trigger(UINT16 IntiFlags, UINT8 Source)
-{
-
- switch (IntiFlags & ACPI_MADT_TRIGGER_MASK) {
- case ACPI_MADT_TRIGGER_CONFORMS:
- if (Source == AcpiGbl_FADT.SciInterrupt)
- return (INTR_TRIGGER_LEVEL);
- else
- return (INTR_TRIGGER_EDGE);
- case ACPI_MADT_TRIGGER_EDGE:
- return (INTR_TRIGGER_EDGE);
- case ACPI_MADT_TRIGGER_LEVEL:
- return (INTR_TRIGGER_LEVEL);
- default:
- panic("Bogus Interrupt Trigger Mode");
- }
-}
-
-/*
- * Find the local APIC ID associated with a given ACPI Processor ID.
- */
-static int
-madt_find_cpu(u_int acpi_id, u_int *apic_id)
-{
- int i;
-
- for (i = 0; i <= MAX_APIC_ID; i++) {
- if (!lapics[i].la_enabled)
- continue;
- if (lapics[i].la_acpi_id != acpi_id)
- continue;
- *apic_id = i;
- return (0);
- }
- return (ENOENT);
-}
-
-/*
- * Find the IO APIC and pin on that APIC associated with a given global
- * interrupt.
- */
-static int
-madt_find_interrupt(int intr, void **apic, u_int *pin)
-{
- int i, best;
-
- best = -1;
- for (i = 0; i <= MAX_APIC_ID; i++) {
- if (ioapics[i].io_apic == NULL ||
- ioapics[i].io_vector > intr)
- continue;
- if (best == -1 ||
- ioapics[best].io_vector < ioapics[i].io_vector)
- best = i;
- }
- if (best == -1)
- return (ENOENT);
- *apic = ioapics[best].io_apic;
- *pin = intr - ioapics[best].io_vector;
- if (*pin > 32)
- printf("WARNING: Found intpin of %u for vector %d\n", *pin,
- intr);
- return (0);
-}
-
-/*
- * Parse an interrupt source override for an ISA interrupt.
- */
-static void
-madt_parse_interrupt_override(ACPI_MADT_INTERRUPT_OVERRIDE *intr)
-{
- void *new_ioapic, *old_ioapic;
- u_int new_pin, old_pin;
- enum intr_trigger trig;
- enum intr_polarity pol;
- char buf[64];
-
- if (acpi_quirks & ACPI_Q_MADT_IRQ0 && intr->SourceIrq == 0 &&
- intr->GlobalIrq == 2) {
- if (bootverbose)
- printf("MADT: Skipping timer override\n");
- return;
- }
- if (bootverbose)
- printf("MADT: Interrupt override: source %u, irq %u\n",
- intr->SourceIrq, intr->GlobalIrq);
- KASSERT(intr->Bus == 0, ("bus for interrupt overrides must be zero"));
- if (madt_find_interrupt(intr->GlobalIrq, &new_ioapic, &new_pin) != 0) {
- printf("MADT: Could not find APIC for vector %u (IRQ %u)\n",
- intr->GlobalIrq, intr->SourceIrq);
- return;
- }
-
- /*
- * Lookup the appropriate trigger and polarity modes for this
- * entry.
- */
- trig = interrupt_trigger(intr->IntiFlags, intr->SourceIrq);
- pol = interrupt_polarity(intr->IntiFlags, intr->SourceIrq);
-
- /*
- * If the SCI is identity mapped but has edge trigger and
- * active-hi polarity or the force_sci_lo tunable is set,
- * force it to use level/lo.
- */
- if (intr->SourceIrq == AcpiGbl_FADT.SciInterrupt) {
- madt_found_sci_override = 1;
- if (getenv_string("hw.acpi.sci.trigger", buf, sizeof(buf))) {
- if (tolower(buf[0]) == 'e')
- trig = INTR_TRIGGER_EDGE;
- else if (tolower(buf[0]) == 'l')
- trig = INTR_TRIGGER_LEVEL;
- else
- panic(
- "Invalid trigger %s: must be 'edge' or 'level'",
- buf);
- printf("MADT: Forcing SCI to %s trigger\n",
- trig == INTR_TRIGGER_EDGE ? "edge" : "level");
- }
- if (getenv_string("hw.acpi.sci.polarity", buf, sizeof(buf))) {
- if (tolower(buf[0]) == 'h')
- pol = INTR_POLARITY_HIGH;
- else if (tolower(buf[0]) == 'l')
- pol = INTR_POLARITY_LOW;
- else
- panic(
- "Invalid polarity %s: must be 'high' or 'low'",
- buf);
- printf("MADT: Forcing SCI to active %s polarity\n",
- pol == INTR_POLARITY_HIGH ? "high" : "low");
- }
- }
-
- /* Remap the IRQ if it is mapped to a different interrupt vector. */
- if (intr->SourceIrq != intr->GlobalIrq) {
- /*
- * If the SCI is remapped to a non-ISA global interrupt,
- * then override the vector we use to setup and allocate
- * the interrupt.
- */
- if (intr->GlobalIrq > 15 &&
- intr->SourceIrq == AcpiGbl_FADT.SciInterrupt)
- acpi_OverrideInterruptLevel(intr->GlobalIrq);
- else
- ioapic_remap_vector(new_ioapic, new_pin,
- intr->SourceIrq);
- if (madt_find_interrupt(intr->SourceIrq, &old_ioapic,
- &old_pin) != 0)
- printf("MADT: Could not find APIC for source IRQ %u\n",
- intr->SourceIrq);
- else if (ioapic_get_vector(old_ioapic, old_pin) ==
- intr->SourceIrq)
- ioapic_disable_pin(old_ioapic, old_pin);
- }
-
- /* Program the polarity and trigger mode. */
- ioapic_set_triggermode(new_ioapic, new_pin, trig);
- ioapic_set_polarity(new_ioapic, new_pin, pol);
-}
-
-/*
- * Parse an entry for an NMI routed to an IO APIC.
- */
-static void
-madt_parse_nmi(ACPI_MADT_NMI_SOURCE *nmi)
-{
- void *ioapic;
- u_int pin;
-
- if (madt_find_interrupt(nmi->GlobalIrq, &ioapic, &pin) != 0) {
- printf("MADT: Could not find APIC for vector %u\n",
- nmi->GlobalIrq);
- return;
- }
-
- ioapic_set_nmi(ioapic, pin);
- if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
- ioapic_set_triggermode(ioapic, pin,
- interrupt_trigger(nmi->IntiFlags, 0));
- if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
- ioapic_set_polarity(ioapic, pin,
- interrupt_polarity(nmi->IntiFlags, 0));
-}
-
-/*
- * Parse an entry for an NMI routed to a local APIC LVT pin.
- */
-static void
-madt_parse_local_nmi(ACPI_MADT_LOCAL_APIC_NMI *nmi)
-{
- u_int apic_id, pin;
-
- if (nmi->ProcessorId == 0xff)
- apic_id = APIC_ID_ALL;
- else if (madt_find_cpu(nmi->ProcessorId, &apic_id) != 0) {
- if (bootverbose)
- printf("MADT: Ignoring local NMI routed to "
- "ACPI CPU %u\n", nmi->ProcessorId);
- return;
- }
- if (nmi->Lint == 0)
- pin = LVT_LINT0;
- else
- pin = LVT_LINT1;
- lapic_set_lvt_mode(apic_id, pin, APIC_LVT_DM_NMI);
- if (!(nmi->IntiFlags & ACPI_MADT_TRIGGER_CONFORMS))
- lapic_set_lvt_triggermode(apic_id, pin,
- interrupt_trigger(nmi->IntiFlags, 0));
- if (!(nmi->IntiFlags & ACPI_MADT_POLARITY_CONFORMS))
- lapic_set_lvt_polarity(apic_id, pin,
- interrupt_polarity(nmi->IntiFlags, 0));
-}
-
-/*
- * Parse interrupt entries.
- */
-static void
-madt_parse_ints(ACPI_SUBTABLE_HEADER *entry, void *arg __unused)
-{
-
- switch (entry->Type) {
- case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
- madt_parse_interrupt_override(
- (ACPI_MADT_INTERRUPT_OVERRIDE *)entry);
- break;
- case ACPI_MADT_TYPE_NMI_SOURCE:
- madt_parse_nmi((ACPI_MADT_NMI_SOURCE *)entry);
- break;
- case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
- madt_parse_local_nmi((ACPI_MADT_LOCAL_APIC_NMI *)entry);
- break;
- }
-}
-
-/*
- * Setup per-CPU ACPI IDs.
- */
-static void
-madt_set_ids(void *dummy)
-{
- struct lapic_info *la;
- struct pcpu *pc;
- u_int i;
-
- if (madt == NULL)
- return;
- CPU_FOREACH(i) {
- pc = pcpu_find(i);
- KASSERT(pc != NULL, ("no pcpu data for CPU %u", i));
- la = &lapics[pc->pc_apic_id];
- if (!la->la_enabled)
- panic("APIC: CPU with APIC ID %u is not enabled",
- pc->pc_apic_id);
- pc->pc_acpi_id = la->la_acpi_id;
- if (bootverbose)
- printf("APIC: CPU %u has ACPI ID %u\n", i,
- la->la_acpi_id);
- }
-}
-SYSINIT(madt_set_ids, SI_SUB_CPU, SI_ORDER_ANY, madt_set_ids, NULL);
diff --git a/sys/amd64/amd64/amd64_mem.c b/sys/amd64/amd64/amd64_mem.c
index 0f7bc25..2768cf4 100644
--- a/sys/amd64/amd64/amd64_mem.c
+++ b/sys/amd64/amd64/amd64_mem.c
@@ -583,7 +583,7 @@ amd64_mrset(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg)
i = (sc->mr_cap & MR686_FIXMTRR) ? MTRR_N64K + MTRR_N16K + MTRR_N4K : 0;
mrd = sc->mr_desc + i;
for (; i < sc->mr_ndesc; i++, mrd++) {
- if (mrd->mr_flags & MDF_ACTIVE)
+ if ((mrd->mr_flags & (MDF_ACTIVE | MDF_BOGUS)) == MDF_ACTIVE)
pmap_demote_DMAP(mrd->mr_base, mrd->mr_len, FALSE);
}
@@ -688,7 +688,7 @@ amd64_mrinit(struct mem_range_softc *sc)
i = (sc->mr_cap & MR686_FIXMTRR) ? MTRR_N64K + MTRR_N16K + MTRR_N4K : 0;
mrd = sc->mr_desc + i;
for (; i < sc->mr_ndesc; i++, mrd++) {
- if (mrd->mr_flags & MDF_ACTIVE)
+ if ((mrd->mr_flags & (MDF_ACTIVE | MDF_BOGUS)) == MDF_ACTIVE)
pmap_demote_DMAP(mrd->mr_base, mrd->mr_len, TRUE);
}
}
diff --git a/sys/amd64/amd64/minidump_machdep.c b/sys/amd64/amd64/minidump_machdep.c
index a9af809..8b5ae7c 100644
--- a/sys/amd64/amd64/minidump_machdep.c
+++ b/sys/amd64/amd64/minidump_machdep.c
@@ -167,63 +167,91 @@ blk_write(struct dumperinfo *di, char *ptr, vm_paddr_t pa, size_t sz)
}
/* A fake page table page, to avoid having to handle both 4K and 2M pages */
-static pt_entry_t fakept[NPTEPG];
+static pd_entry_t fakepd[NPDEPG];
void
minidumpsys(struct dumperinfo *di)
{
uint64_t dumpsize;
- uint32_t ptesize;
+ uint32_t pmapsize;
vm_offset_t va;
int error;
uint64_t bits;
uint64_t *pdp, *pd, *pt, pa;
- int i, j, k, bit;
+ int i, j, k, n, bit;
+ int retry_count;
struct minidumphdr mdhdr;
+ retry_count = 0;
+ retry:
+ retry_count++;
counter = 0;
/* Walk page table pages, set bits in vm_page_dump */
- ptesize = 0;
+ pmapsize = 0;
pdp = (uint64_t *)PHYS_TO_DMAP(KPDPphys);
for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR,
- kernel_vm_end); va += NBPDR) {
- i = (va >> PDPSHIFT) & ((1ul << NPDPEPGSHIFT) - 1);
+ kernel_vm_end); ) {
/*
* We always write a page, even if it is zero. Each
- * page written corresponds to 2MB of space
+ * page written corresponds to 1GB of space
*/
- ptesize += PAGE_SIZE;
- if ((pdp[i] & PG_V) == 0)
+ pmapsize += PAGE_SIZE;
+ i = (va >> PDPSHIFT) & ((1ul << NPDPEPGSHIFT) - 1);
+ if ((pdp[i] & PG_V) == 0) {
+ va += NBPDP;
continue;
- pd = (uint64_t *)PHYS_TO_DMAP(pdp[i] & PG_FRAME);
- j = ((va >> PDRSHIFT) & ((1ul << NPDEPGSHIFT) - 1));
- if ((pd[j] & (PG_PS | PG_V)) == (PG_PS | PG_V)) {
- /* This is an entire 2M page. */
- pa = pd[j] & PG_PS_FRAME;
- for (k = 0; k < NPTEPG; k++) {
+ }
+
+ /*
+ * 1GB page is represented as 512 2MB pages in a dump.
+ */
+ if ((pdp[i] & PG_PS) != 0) {
+ va += NBPDP;
+ pa = pdp[i] & PG_PS_FRAME;
+ for (n = 0; n < NPDEPG * NPTEPG; n++) {
if (is_dumpable(pa))
dump_add_page(pa);
pa += PAGE_SIZE;
}
continue;
}
- if ((pd[j] & PG_V) == PG_V) {
- /* set bit for each valid page in this 2MB block */
- pt = (uint64_t *)PHYS_TO_DMAP(pd[j] & PG_FRAME);
- for (k = 0; k < NPTEPG; k++) {
- if ((pt[k] & PG_V) == PG_V) {
- pa = pt[k] & PG_FRAME;
+
+ pd = (uint64_t *)PHYS_TO_DMAP(pdp[i] & PG_FRAME);
+ for (n = 0; n < NPDEPG; n++, va += NBPDR) {
+ j = (va >> PDRSHIFT) & ((1ul << NPDEPGSHIFT) - 1);
+
+ if ((pd[j] & PG_V) == 0)
+ continue;
+
+ if ((pd[j] & PG_PS) != 0) {
+ /* This is an entire 2M page. */
+ pa = pd[j] & PG_PS_FRAME;
+ for (k = 0; k < NPTEPG; k++) {
if (is_dumpable(pa))
dump_add_page(pa);
+ pa += PAGE_SIZE;
}
+ continue;
+ }
+
+ pa = pd[j] & PG_FRAME;
+ /* set bit for this PTE page */
+ if (is_dumpable(pa))
+ dump_add_page(pa);
+ /* and for each valid page in this 2MB block */
+ pt = (uint64_t *)PHYS_TO_DMAP(pd[j] & PG_FRAME);
+ for (k = 0; k < NPTEPG; k++) {
+ if ((pt[k] & PG_V) == 0)
+ continue;
+ pa = pt[k] & PG_FRAME;
+ if (is_dumpable(pa))
+ dump_add_page(pa);
}
- } else {
- /* nothing, we're going to dump a null page */
}
}
/* Calculate dump size. */
- dumpsize = ptesize;
+ dumpsize = pmapsize;
dumpsize += round_page(msgbufp->msg_size);
dumpsize += round_page(vm_page_dump_size);
for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) {
@@ -244,7 +272,7 @@ minidumpsys(struct dumperinfo *di)
/* Determine dump offset on device. */
if (di->mediasize < SIZEOF_METADATA + dumpsize + sizeof(kdh) * 2) {
- error = ENOSPC;
+ error = E2BIG;
goto fail;
}
dumplo = di->mediaoffset + di->mediasize - dumpsize;
@@ -257,7 +285,7 @@ minidumpsys(struct dumperinfo *di)
mdhdr.version = MINIDUMP_VERSION;
mdhdr.msgbufsize = msgbufp->msg_size;
mdhdr.bitmapsize = vm_page_dump_size;
- mdhdr.ptesize = ptesize;
+ mdhdr.pmapsize = pmapsize;
mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
mdhdr.dmapbase = DMAP_MIN_ADDRESS;
mdhdr.dmapend = DMAP_MAX_ADDRESS;
@@ -274,9 +302,9 @@ minidumpsys(struct dumperinfo *di)
dumplo += sizeof(kdh);
/* Dump my header */
- bzero(&fakept, sizeof(fakept));
- bcopy(&mdhdr, &fakept, sizeof(mdhdr));
- error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE);
+ bzero(&fakepd, sizeof(fakepd));
+ bcopy(&mdhdr, &fakepd, sizeof(mdhdr));
+ error = blk_write(di, (char *)&fakepd, 0, PAGE_SIZE);
if (error)
goto fail;
@@ -290,55 +318,49 @@ minidumpsys(struct dumperinfo *di)
if (error)
goto fail;
- /* Dump kernel page table pages */
+ /* Dump kernel page directory pages */
+ bzero(fakepd, sizeof(fakepd));
pdp = (uint64_t *)PHYS_TO_DMAP(KPDPphys);
for (va = VM_MIN_KERNEL_ADDRESS; va < MAX(KERNBASE + NKPT * NBPDR,
- kernel_vm_end); va += NBPDR) {
+ kernel_vm_end); va += NBPDP) {
i = (va >> PDPSHIFT) & ((1ul << NPDPEPGSHIFT) - 1);
+
/* We always write a page, even if it is zero */
if ((pdp[i] & PG_V) == 0) {
- bzero(fakept, sizeof(fakept));
- error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE);
+ error = blk_write(di, (char *)&fakepd, 0, PAGE_SIZE);
if (error)
goto fail;
- /* flush, in case we reuse fakept in the same block */
+ /* flush, in case we reuse fakepd in the same block */
error = blk_flush(di);
if (error)
goto fail;
continue;
}
- pd = (uint64_t *)PHYS_TO_DMAP(pdp[i] & PG_FRAME);
- j = ((va >> PDRSHIFT) & ((1ul << NPDEPGSHIFT) - 1));
- if ((pd[j] & (PG_PS | PG_V)) == (PG_PS | PG_V)) {
- /* This is a single 2M block. Generate a fake PTP */
- pa = pd[j] & PG_PS_FRAME;
- for (k = 0; k < NPTEPG; k++) {
- fakept[k] = (pa + (k * PAGE_SIZE)) | PG_V | PG_RW | PG_A | PG_M;
- }
- error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE);
+
+ /* 1GB page is represented as 512 2MB pages in a dump */
+ if ((pdp[i] & PG_PS) != 0) {
+ /* PDPE and PDP have identical layout in this case */
+ fakepd[0] = pdp[i];
+ for (j = 1; j < NPDEPG; j++)
+ fakepd[j] = fakepd[j - 1] + NBPDR;
+ error = blk_write(di, (char *)&fakepd, 0, PAGE_SIZE);
if (error)
goto fail;
- /* flush, in case we reuse fakept in the same block */
+ /* flush, in case we reuse fakepd in the same block */
error = blk_flush(di);
if (error)
goto fail;
+ bzero(fakepd, sizeof(fakepd));
continue;
}
- if ((pd[j] & PG_V) == PG_V) {
- pt = (uint64_t *)PHYS_TO_DMAP(pd[j] & PG_FRAME);
- error = blk_write(di, (char *)pt, 0, PAGE_SIZE);
- if (error)
- goto fail;
- } else {
- bzero(fakept, sizeof(fakept));
- error = blk_write(di, (char *)&fakept, 0, PAGE_SIZE);
- if (error)
- goto fail;
- /* flush, in case we reuse fakept in the same block */
- error = blk_flush(di);
- if (error)
- goto fail;
- }
+
+ pd = (uint64_t *)PHYS_TO_DMAP(pdp[i] & PG_FRAME);
+ error = blk_write(di, (char *)pd, 0, PAGE_SIZE);
+ if (error)
+ goto fail;
+ error = blk_flush(di);
+ if (error)
+ goto fail;
}
/* Dump memory chunks */
@@ -374,12 +396,21 @@ minidumpsys(struct dumperinfo *di)
if (error < 0)
error = -error;
- if (error == ECANCELED)
- printf("\nDump aborted\n");
- else if (error == ENOSPC)
- printf("\nDump failed. Partition too small.\n");
+ printf("\n");
+ if (error == ENOSPC) {
+ printf("Dump map grown while dumping. ");
+ if (retry_count < 5) {
+ printf("Retrying...\n");
+ goto retry;
+ }
+ printf("Dump failed.\n");
+ }
+ else if (error == ECANCELED)
+ printf("Dump aborted\n");
+ else if (error == E2BIG)
+ printf("Dump failed. Partition too small.\n");
else
- printf("\n** DUMP FAILED (ERROR %d) **\n", error);
+ printf("** DUMP FAILED (ERROR %d) **\n", error);
}
void
diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index f2951da..07380ff 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
@@ -422,7 +422,7 @@ cpu_add(u_int apic_id, char boot_cpu)
}
if (mp_ncpus < MAXCPU) {
mp_ncpus++;
- mp_maxid = mp_ncpus -1;
+ mp_maxid = mp_ncpus - 1;
}
if (bootverbose)
printf("SMP: Added CPU %d (%s)\n", apic_id, boot_cpu ? "BSP" :
@@ -445,7 +445,7 @@ cpu_mp_setmaxid(void)
else
KASSERT(mp_maxid >= mp_ncpus - 1,
("%s: counters out of sync: max %d, count %d", __func__,
- mp_maxid, mp_ncpus));
+ mp_maxid, mp_ncpus));
}
int
diff --git a/sys/amd64/include/apm_bios.h b/sys/amd64/include/apm_bios.h
index 424852d..9cc0eee 100644
--- a/sys/amd64/include/apm_bios.h
+++ b/sys/amd64/include/apm_bios.h
@@ -1,264 +1,6 @@
/*-
- * APM (Advanced Power Management) BIOS Device Driver
- *
- * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
- *
- * This software may be used, modified, copied, and distributed, in
- * both source and binary form provided that the above copyright and
- * these terms are retained. Under no circumstances is the author
- * responsible for the proper functioning of this software, nor does
- * the author assume any responsibility for damages incurred with its
- * use.
- *
- * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
- *
- * $FreeBSD$
+ * This file is in the public domain.
*/
+/* $FreeBSD$ */
-#ifndef _MACHINE_APM_BIOS_H_
-#define _MACHINE_APM_BIOS_H_
-
-#ifndef _KERNEL
-#include <sys/types.h>
-#endif
-#include <sys/ioccom.h>
-
-/* BIOS id */
-#define APM_BIOS 0x53
-#define APM_INT 0x15
-
-/* APM flags */
-#define APM_16BIT_SUPPORT 0x01
-#define APM_32BIT_SUPPORT 0x02
-#define APM_CPUIDLE_SLOW 0x04
-#define APM_DISABLED 0x08
-#define APM_DISENGAGED 0x10
-
-/* APM initializer physical address */
-#define APM_OURADDR 0x00080000
-
-/* APM functions */
-#define APM_INSTCHECK 0x00
-#define APM_REALCONNECT 0x01
-#define APM_PROT16CONNECT 0x02
-#define APM_PROT32CONNECT 0x03
-#define APM_DISCONNECT 0x04
-#define APM_CPUIDLE 0x05
-#define APM_CPUBUSY 0x06
-#define APM_SETPWSTATE 0x07
-#define APM_ENABLEDISABLEPM 0x08
-#define APM_RESTOREDEFAULT 0x09
-#define APM_GETPWSTATUS 0x0a
-#define APM_GETPMEVENT 0x0b
-#define APM_GETPWSTATE 0x0c
-#define APM_ENABLEDISABLEDPM 0x0d
-#define APM_DRVVERSION 0x0e
-#define APM_ENGAGEDISENGAGEPM 0x0f
-#define APM_GETCAPABILITIES 0x10
-#define APM_RESUMETIMER 0x11
-#define APM_RESUMEONRING 0x12
-#define APM_TIMERREQUESTS 0x13
-#define APM_OEMFUNC 0x80
-
-/* error code */
-#define APME_OK 0x00
-#define APME_PMDISABLED 0x01
-#define APME_REALESTABLISHED 0x02
-#define APME_NOTCONNECTED 0x03
-#define APME_PROT16ESTABLISHED 0x05
-#define APME_PROT16NOTSUPPORTED 0x06
-#define APME_PROT32ESTABLISHED 0x07
-#define APME_PROT32NOTDUPPORTED 0x08
-#define APME_UNKNOWNDEVICEID 0x09
-#define APME_OUTOFRANGE 0x0a
-#define APME_NOTENGAGED 0x0b
-#define APME_CANTENTERSTATE 0x60
-#define APME_NOPMEVENT 0x80
-#define APME_NOAPMPRESENT 0x86
-
-
-/* device code */
-#define PMDV_APMBIOS 0x0000
-#define PMDV_ALLDEV 0x0001
-#define PMDV_DISP0 0x0100
-#define PMDV_DISP1 0x0101
-#define PMDV_DISPALL 0x01ff
-#define PMDV_2NDSTORAGE0 0x0200
-#define PMDV_2NDSTORAGE1 0x0201
-#define PMDV_2NDSTORAGE2 0x0202
-#define PMDV_2NDSTORAGE3 0x0203
-#define PMDV_PARALLEL0 0x0300
-#define PMDV_PARALLEL1 0x0301
-#define PMDV_SERIAL0 0x0400
-#define PMDV_SERIAL1 0x0401
-#define PMDV_SERIAL2 0x0402
-#define PMDV_SERIAL3 0x0403
-#define PMDV_SERIAL4 0x0404
-#define PMDV_SERIAL5 0x0405
-#define PMDV_SERIAL6 0x0406
-#define PMDV_SERIAL7 0x0407
-#define PMDV_NET0 0x0500
-#define PMDV_NET1 0x0501
-#define PMDV_NET2 0x0502
-#define PMDV_NET3 0x0503
-#define PMDV_PCMCIA0 0x0600
-#define PMDV_PCMCIA1 0x0601
-#define PMDV_PCMCIA2 0x0602
-#define PMDV_PCMCIA3 0x0603
-/* 0x0700 - 0x7fff Reserved */
-#define PMDV_BATT_BASE 0x8000
-#define PMDV_BATT0 0x8001
-#define PMDV_BATT1 0x8002
-#define PMDV_BATT_ALL 0x80ff
-/* 0x8100 - 0xdfff Reserved */
-/* 0xe000 - 0xefff OEM-defined power device IDs */
-/* 0xf000 - 0xffff Reserved */
-
-/* Power state */
-#define PMST_APMENABLED 0x0000
-#define PMST_STANDBY 0x0001
-#define PMST_SUSPEND 0x0002
-#define PMST_OFF 0x0003
-#define PMST_LASTREQNOTIFY 0x0004
-#define PMST_LASTREQREJECT 0x0005
-/* 0x0006 - 0x001f Reserved system states */
-/* 0x0020 - 0x003f OEM-defined system states */
-/* 0x0040 - 0x007f OEM-defined device states */
-/* 0x0080 - 0xffff Reserved device states */
-
-#if !defined(ASSEMBLER) && !defined(INITIALIZER)
-
-/* C definitions */
-struct apmhook {
- struct apmhook *ah_next;
- int (*ah_fun)(void *ah_arg);
- void *ah_arg;
- const char *ah_name;
- int ah_order;
-};
-#define APM_HOOK_NONE (-1)
-#define APM_HOOK_SUSPEND 0
-#define APM_HOOK_RESUME 1
-#define NAPM_HOOK 2
-
-#ifdef _KERNEL
-
-void apm_suspend(int state);
-struct apmhook *apm_hook_establish (int apmh, struct apmhook *);
-void apm_hook_disestablish (int apmh, struct apmhook *);
-void apm_cpu_idle(void);
-void apm_cpu_busy(void);
-
-#endif
-
-#endif /* !ASSEMBLER && !INITIALIZER */
-
-#define APM_MIN_ORDER 0x00
-#define APM_MID_ORDER 0x80
-#define APM_MAX_ORDER 0xff
-
-/* power management event code */
-#define PMEV_NOEVENT 0x0000
-#define PMEV_STANDBYREQ 0x0001
-#define PMEV_SUSPENDREQ 0x0002
-#define PMEV_NORMRESUME 0x0003
-#define PMEV_CRITRESUME 0x0004
-#define PMEV_BATTERYLOW 0x0005
-#define PMEV_POWERSTATECHANGE 0x0006
-#define PMEV_UPDATETIME 0x0007
-#define PMEV_CRITSUSPEND 0x0008
-#define PMEV_USERSTANDBYREQ 0x0009
-#define PMEV_USERSUSPENDREQ 0x000a
-#define PMEV_STANDBYRESUME 0x000b
-#define PMEV_CAPABILITIESCHANGE 0x000c
-/* 0x000d - 0x00ff Reserved system events */
-/* 0x0100 - 0x01ff Reserved device events */
-/* 0x0200 - 0x02ff OEM-defined APM events */
-/* 0x0300 - 0xffff Reserved */
-#define PMEV_DEFAULT 0xffffffff /* used for customization */
-
-#if !defined(ASSEMBLER) && !defined(INITIALIZER)
-
-/*
- * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This
- * is for backward compatibility with old executables.
- */
-typedef struct apm_info_old {
- u_int ai_major; /* APM major version */
- u_int ai_minor; /* APM minor version */
- u_int ai_acline; /* AC line status */
- u_int ai_batt_stat; /* Battery status */
- u_int ai_batt_life; /* Remaining battery life */
- u_int ai_status; /* Status of APM support (enabled/disabled) */
-} *apm_info_old_t;
-
-/*
- * Structure returned by the APMIO_GETINFO ioctl.
- *
- * In the comments below, the parenthesized numbers indicate the minimum
- * value of ai_infoversion for which each field is valid.
- */
-typedef struct apm_info {
- u_int ai_infoversion; /* Indicates which fields are valid */
- u_int ai_major; /* APM major version (0) */
- u_int ai_minor; /* APM minor version (0) */
- u_int ai_acline; /* AC line status (0) */
- u_int ai_batt_stat; /* Battery status (0) */
- u_int ai_batt_life; /* Remaining battery life in percent (0) */
- int ai_batt_time; /* Remaining battery time in seconds (0) */
- u_int ai_status; /* True if enabled (0) */
- u_int ai_batteries; /* Number of batteries (1) */
- u_int ai_capabilities;/* APM Capabilities (1) */
- u_int ai_spare[6]; /* For future expansion */
-} *apm_info_t;
-
-/* Battery flag */
-#define APM_BATT_HIGH 0x01
-#define APM_BATT_LOW 0x02
-#define APM_BATT_CRITICAL 0x04
-#define APM_BATT_CHARGING 0x08
-#define APM_BATT_NOT_PRESENT 0x10
-#define APM_BATT_NO_SYSTEM 0x80
-
-typedef struct apm_pwstatus {
- u_int ap_device; /* Device code of battery */
- u_int ap_acline; /* AC line status (0) */
- u_int ap_batt_stat; /* Battery status (0) */
- u_int ap_batt_flag; /* Battery flag (0) */
- u_int ap_batt_life; /* Remaining battery life in percent (0) */
- int ap_batt_time; /* Remaining battery time in seconds (0) */
-} *apm_pwstatus_t;
-
-struct apm_bios_arg {
- uint32_t eax;
- uint32_t ebx;
- uint32_t ecx;
- uint32_t edx;
- uint32_t esi;
- uint32_t edi;
-};
-
-struct apm_event_info {
- u_int type;
- u_int index;
- u_int spare[8];
-};
-
-#define APMIO_SUSPEND _IO('P', 1)
-#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old)
-#define APMIO_ENABLE _IO('P', 5)
-#define APMIO_DISABLE _IO('P', 6)
-#define APMIO_HALTCPU _IO('P', 7)
-#define APMIO_NOTHALTCPU _IO('P', 8)
-#define APMIO_DISPLAY _IOW('P', 9, int)
-#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg)
-#define APMIO_GETINFO _IOR('P', 11, struct apm_info)
-#define APMIO_STANDBY _IO('P', 12)
-#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus)
-/* for /dev/apmctl */
-#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info)
-#define APMIO_REJECTLASTREQ _IO('P', 101)
-
-#endif /* !ASSEMBLER && !INITIALIZER */
-
-#endif /* !_MACHINE_APM_BIOS_H_ */
+#include <x86/apm_bios.h>
diff --git a/sys/amd64/include/minidump.h b/sys/amd64/include/minidump.h
index 1ea92b7..2ac529c 100644
--- a/sys/amd64/include/minidump.h
+++ b/sys/amd64/include/minidump.h
@@ -30,14 +30,14 @@
#define _MACHINE_MINIDUMP_H_ 1
#define MINIDUMP_MAGIC "minidump FreeBSD/amd64"
-#define MINIDUMP_VERSION 1
+#define MINIDUMP_VERSION 2
struct minidumphdr {
char magic[24];
uint32_t version;
uint32_t msgbufsize;
uint32_t bitmapsize;
- uint32_t ptesize;
+ uint32_t pmapsize;
uint64_t kernbase;
uint64_t dmapbase;
uint64_t dmapend;
diff --git a/sys/amd64/include/mutex.h b/sys/amd64/include/mutex.h
deleted file mode 100644
index a2edadd..0000000
--- a/sys/amd64/include/mutex.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*-
- * Copyright (c) 1997 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.
- * 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. Berkeley Software Design Inc's name may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * 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.
- *
- * from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#endif /* __MACHINE_MUTEX_H */
diff --git a/sys/arm/conf/AVILA b/sys/arm/conf/AVILA
index 49b8ed9..db1c3a0 100644
--- a/sys/arm/conf/AVILA
+++ b/sys/arm/conf/AVILA
@@ -87,6 +87,10 @@ device ad7418 # AD7418 on I2C bus
device avila_led
+device gpio
+device gpioled
+device avila_gpio # GPIO pins on J8
+
device ata
device atadisk # ATA disk drives
device avila_ata # Gateworks CF/IDE support
diff --git a/sys/arm/conf/AVILA.hints b/sys/arm/conf/AVILA.hints
index 67483ef..38b5b05 100644
--- a/sys/arm/conf/AVILA.hints
+++ b/sys/arm/conf/AVILA.hints
@@ -41,6 +41,9 @@ hint.ata_avila.0.at="ixp0"
# Front Panel LED
hint.led_avila.0.at="ixp0"
+# GPIO pins
+hint.gpio_avila.0.at="ixp0"
+
# Analog Devices AD7418 temperature sensor
hint.ad7418.0.at="iicbus0"
hint.ad7418.0.addr=0x50
diff --git a/sys/arm/conf/BWCT.hints b/sys/arm/conf/BWCT.hints
index 0a520c3..1d3a212 100644
--- a/sys/arm/conf/BWCT.hints
+++ b/sys/arm/conf/BWCT.hints
@@ -7,3 +7,7 @@ hint.ds1672_rtc.0.addr=0xd0
# National Semiconductor LM75 temperature sensor sitting on the I2C bus
hint.lm75.0.at="iicbus0"
hint.lm75.0.addr=0x9e
+
+# Atmel SPIflash sitting on the spibus
+hint.at45d.0.at="spibus0"
+hint.at45d.0.addr=0x00
diff --git a/sys/arm/include/cpuconf.h b/sys/arm/include/cpuconf.h
index c8a9b6e..7fa6157 100644
--- a/sys/arm/include/cpuconf.h
+++ b/sys/arm/include/cpuconf.h
@@ -70,7 +70,7 @@
*/
#if (defined(CPU_ARM7TDMI) || defined(CPU_ARM8) || defined(CPU_ARM9) || \
defined(CPU_SA110) || defined(CPU_SA1100) || defined(CPU_SA1110) || \
- defined(CPU_IXP12X0) || defined(CPU_XSCALE_IXP425) || defined(CPU_FA526))
+ defined(CPU_IXP12X0) || defined(CPU_FA526))
#define ARM_ARCH_4 1
#else
#define ARM_ARCH_4 0
@@ -79,7 +79,8 @@
#if (defined(CPU_ARM9E) || defined(CPU_ARM10) || \
defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
defined(CPU_XSCALE_80219) || defined(CPU_XSCALE_81342) || \
- defined(CPU_XSCALE_PXA2X0) || defined(CPU_FA626TE))
+ defined(CPU_XSCALE_PXA2X0) || defined(CPU_XSCALE_IXP425) || \
+ defined(CPU_FA626TE))
#define ARM_ARCH_5 1
#else
#define ARM_ARCH_5 0
@@ -141,9 +142,9 @@
#define ARM_MMU_SA1 0
#endif
-#if(defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
- defined(CPU_XSCALE_PXA2X0) || defined(CPU_XSCALE_IXP425) || \
- defined(CPU_XSCALE_80219)) || defined(CPU_XSCALE_81342)
+#if (defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
+ defined(CPU_XSCALE_PXA2X0) || defined(CPU_XSCALE_IXP425) || \
+ defined(CPU_XSCALE_80219) || defined(CPU_XSCALE_81342))
#define ARM_MMU_XSCALE 1
#else
#define ARM_MMU_XSCALE 0
@@ -162,7 +163,7 @@
*/
#if (defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
- defined(CPU_XSCALE_80219)) || defined(CPU_XSCALE_81342)
+ defined(CPU_XSCALE_80219) || defined(CPU_XSCALE_81342))
#define ARM_XSCALE_PMU 1
#else
#define ARM_XSCALE_PMU 0
diff --git a/sys/arm/include/mutex.h b/sys/arm/include/mutex.h
deleted file mode 100644
index c9b2e1d..0000000
--- a/sys/arm/include/mutex.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-
- * Copyright (c) 2001 Jake Burkholder.
- * 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$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#endif /* !_MACHINE_MUTEX_H_ */
diff --git a/sys/arm/xscale/ixp425/avila_gpio.c b/sys/arm/xscale/ixp425/avila_gpio.c
new file mode 100644
index 0000000..82103a1
--- /dev/null
+++ b/sys/arm/xscale/ixp425/avila_gpio.c
@@ -0,0 +1,380 @@
+/*-
+ * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
+ * Copyright (c) 2009, Luiz Otavio O Souza.
+ * Copyright (c) 2010, Andrew Thompson <thompsa@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 unmodified, 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.
+ */
+
+/*
+ * GPIO driver for Gateworks Avilia
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/rman.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/gpio.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <arm/xscale/ixp425/ixp425reg.h>
+#include <arm/xscale/ixp425/ixp425var.h>
+
+#include "gpio_if.h"
+
+#define GPIO_SET_BITS(sc, reg, bits) \
+ GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) | (bits))
+
+#define GPIO_CLEAR_BITS(sc, reg, bits) \
+ GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) & ~(bits))
+
+#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
+#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
+#define GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
+
+struct avila_gpio_softc {
+ device_t sc_dev;
+ struct mtx sc_mtx;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_gpio_ioh;
+ uint32_t sc_valid;
+ struct gpio_pin sc_pins[IXP4XX_GPIO_PINS];
+};
+
+struct avila_gpio_pin {
+ const char *name;
+ int pin;
+ int caps;
+};
+
+#define GPIO_PIN_IO (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)
+static struct avila_gpio_pin avila_gpio_pins[] = {
+ { "GPIO0", 0, GPIO_PIN_IO },
+ { "GPIO1", 1, GPIO_PIN_IO },
+ { "GPIO2", 2, GPIO_PIN_IO },
+ { "GPIO3", 3, GPIO_PIN_IO },
+ { "GPIO4", 4, GPIO_PIN_IO },
+ /*
+ * The following pins are connected to system devices and should not
+ * really be frobbed.
+ */
+#if 0
+ { "SER_ENA", 5, GPIO_PIN_IO },
+ { "I2C_SCL", 6, GPIO_PIN_IO },
+ { "I2C_SDA", 7, GPIO_PIN_IO },
+ { "PCI_INTD", 8, GPIO_PIN_IO },
+ { "PCI_INTC", 9, GPIO_PIN_IO },
+ { "PCI_INTB", 10, GPIO_PIN_IO },
+ { "PCI_INTA", 11, GPIO_PIN_IO },
+ { "ATA_INT", 12, GPIO_PIN_IO },
+ { "PCI_RST", 13, GPIO_PIN_IO },
+ { "PCI_CLK", 14, GPIO_PIN_OUTPUT },
+ { "EX_CLK", 15, GPIO_PIN_OUTPUT },
+#endif
+};
+#undef GPIO_PIN_IO
+
+/*
+ * Helpers
+ */
+static void avila_gpio_pin_configure(struct avila_gpio_softc *sc,
+ struct gpio_pin *pin, uint32_t flags);
+static int avila_gpio_pin_flags(struct avila_gpio_softc *sc, uint32_t pin);
+
+/*
+ * Driver stuff
+ */
+static int avila_gpio_probe(device_t dev);
+static int avila_gpio_attach(device_t dev);
+static int avila_gpio_detach(device_t dev);
+
+/*
+ * GPIO interface
+ */
+static int avila_gpio_pin_max(device_t dev, int *maxpin);
+static int avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
+static int avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
+ *flags);
+static int avila_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
+static int avila_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
+static int avila_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
+static int avila_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);
+static int avila_gpio_pin_toggle(device_t dev, uint32_t pin);
+
+static int
+avila_gpio_pin_flags(struct avila_gpio_softc *sc, uint32_t pin)
+{
+ uint32_t v;
+
+ v = GPIO_CONF_READ_4(sc, IXP425_GPIO_GPINR) & (1 << pin);
+
+ return (v ? GPIO_PIN_INPUT : GPIO_PIN_OUTPUT);
+}
+
+static void
+avila_gpio_pin_configure(struct avila_gpio_softc *sc, struct gpio_pin *pin,
+ unsigned int flags)
+{
+ uint32_t mask;
+
+ mask = 1 << pin->gp_pin;
+ GPIO_LOCK(sc);
+
+ /*
+ * Manage input/output
+ */
+ if (flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) {
+ pin->gp_flags &= ~(GPIO_PIN_INPUT|GPIO_PIN_OUTPUT);
+ if (flags & GPIO_PIN_OUTPUT) {
+ pin->gp_flags |= GPIO_PIN_OUTPUT;
+ GPIO_CLEAR_BITS(sc, IXP425_GPIO_GPOER, mask);
+ }
+ else {
+ pin->gp_flags |= GPIO_PIN_INPUT;
+ GPIO_SET_BITS(sc, IXP425_GPIO_GPOER, mask);
+ }
+ }
+
+ GPIO_UNLOCK(sc);
+}
+
+static int
+avila_gpio_pin_max(device_t dev, int *maxpin)
+{
+
+ *maxpin = IXP4XX_GPIO_PINS - 1;
+ return (0);
+}
+
+static int
+avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & (1 << pin)))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ *caps = sc->sc_pins[pin].gp_caps;
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & (1 << pin)))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ /* refresh since we do not own all the pins */
+ sc->sc_pins[pin].gp_flags = avila_gpio_pin_flags(sc, pin);
+ *flags = sc->sc_pins[pin].gp_flags;
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & (1 << pin)))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ memcpy(name, sc->sc_pins[pin].gp_name, GPIOMAXNAME);
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+ uint32_t mask = 1 << pin;
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
+ return (EINVAL);
+
+ /* Filter out unwanted flags */
+ if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
+ return (EINVAL);
+
+ /* Can't mix input/output together */
+ if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) ==
+ (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT))
+ return (EINVAL);
+
+ avila_gpio_pin_configure(sc, &sc->sc_pins[pin], flags);
+ return (0);
+}
+
+static int
+avila_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+ uint32_t mask = 1 << pin;
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ if (value)
+ GPIO_SET_BITS(sc, IXP425_GPIO_GPOUTR, mask);
+ else
+ GPIO_CLEAR_BITS(sc, IXP425_GPIO_GPOUTR, mask);
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & (1 << pin)))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ *val = (GPIO_CONF_READ_4(sc, IXP425_GPIO_GPINR) & (1 << pin)) ? 1 : 0;
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_pin_toggle(device_t dev, uint32_t pin)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+ uint32_t mask = 1 << pin;
+ int res;
+
+ if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
+ return (EINVAL);
+
+ GPIO_LOCK(sc);
+ res = (GPIO_CONF_READ_4(sc, IXP425_GPIO_GPINR) & mask) ? 1 : 0;
+ if (res)
+ GPIO_CLEAR_BITS(sc, IXP425_GPIO_GPOUTR, mask);
+ else
+ GPIO_SET_BITS(sc, IXP425_GPIO_GPOUTR, mask);
+ GPIO_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+avila_gpio_probe(device_t dev)
+{
+
+ device_set_desc(dev, "Gateworks Avila GPIO driver");
+ return (0);
+}
+
+static int
+avila_gpio_attach(device_t dev)
+{
+#define N(a) (sizeof(a) / sizeof(a[0]))
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+ struct ixp425_softc *sa = device_get_softc(device_get_parent(dev));
+ int i;
+
+ sc->sc_dev = dev;
+ sc->sc_iot = sa->sc_iot;
+ sc->sc_gpio_ioh = sa->sc_gpio_ioh;
+
+ mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
+ MTX_DEF);
+
+ for (i = 0; i < N(avila_gpio_pins); i++) {
+ struct avila_gpio_pin *p = &avila_gpio_pins[i];
+
+ strncpy(sc->sc_pins[p->pin].gp_name, p->name, GPIOMAXNAME);
+ sc->sc_pins[p->pin].gp_pin = p->pin;
+ sc->sc_pins[p->pin].gp_caps = p->caps;
+ sc->sc_pins[p->pin].gp_flags = avila_gpio_pin_flags(sc, p->pin);
+ sc->sc_valid |= 1 << p->pin;
+ }
+
+ device_add_child(dev, "gpioc", device_get_unit(dev));
+ device_add_child(dev, "gpiobus", device_get_unit(dev));
+ return (bus_generic_attach(dev));
+#undef N
+}
+
+static int
+avila_gpio_detach(device_t dev)
+{
+ struct avila_gpio_softc *sc = device_get_softc(dev);
+
+ KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
+
+ bus_generic_detach(dev);
+
+ mtx_destroy(&sc->sc_mtx);
+
+ return(0);
+}
+
+static device_method_t gpio_avila_methods[] = {
+ DEVMETHOD(device_probe, avila_gpio_probe),
+ DEVMETHOD(device_attach, avila_gpio_attach),
+ DEVMETHOD(device_detach, avila_gpio_detach),
+
+ /* GPIO protocol */
+ DEVMETHOD(gpio_pin_max, avila_gpio_pin_max),
+ DEVMETHOD(gpio_pin_getname, avila_gpio_pin_getname),
+ DEVMETHOD(gpio_pin_getflags, avila_gpio_pin_getflags),
+ DEVMETHOD(gpio_pin_getcaps, avila_gpio_pin_getcaps),
+ DEVMETHOD(gpio_pin_setflags, avila_gpio_pin_setflags),
+ DEVMETHOD(gpio_pin_get, avila_gpio_pin_get),
+ DEVMETHOD(gpio_pin_set, avila_gpio_pin_set),
+ DEVMETHOD(gpio_pin_toggle, avila_gpio_pin_toggle),
+ {0, 0},
+};
+
+static driver_t gpio_avila_driver = {
+ "gpio_avila",
+ gpio_avila_methods,
+ sizeof(struct avila_gpio_softc),
+};
+static devclass_t gpio_avila_devclass;
+
+DRIVER_MODULE(gpio_avila, ixp, gpio_avila_driver, gpio_avila_devclass, 0, 0);
diff --git a/sys/arm/xscale/ixp425/files.avila b/sys/arm/xscale/ixp425/files.avila
index 4739401..38b9329 100644
--- a/sys/arm/xscale/ixp425/files.avila
+++ b/sys/arm/xscale/ixp425/files.avila
@@ -2,6 +2,7 @@
arm/xscale/ixp425/avila_machdep.c standard
arm/xscale/ixp425/avila_ata.c optional avila_ata
arm/xscale/ixp425/avila_led.c optional avila_led
+arm/xscale/ixp425/avila_gpio.c optional avila_gpio
arm/xscale/ixp425/cambria_exp_space.c standard
arm/xscale/ixp425/cambria_fled.c optional cambria_fled
arm/xscale/ixp425/cambria_led.c optional cambria_led
diff --git a/sys/arm/xscale/ixp425/ixp425_qmgr.c b/sys/arm/xscale/ixp425/ixp425_qmgr.c
index 2c6ff56..f8792a8 100644
--- a/sys/arm/xscale/ixp425/ixp425_qmgr.c
+++ b/sys/arm/xscale/ixp425/ixp425_qmgr.c
@@ -317,7 +317,7 @@ ixpqmgr_attach(device_t dev)
sc->aqmFreeSramAddress = 0x100; /* Q buffer space starts at 0x2100 */
- ixpqmgr_rebuild(sc); /* build inital priority table */
+ ixpqmgr_rebuild(sc); /* build initial priority table */
aqm_reset(sc); /* reset h/w */
return (0);
}
@@ -775,7 +775,7 @@ ixpqmgr_intr(void *arg)
*
* The search will end when all the bits of the interrupt
* register are cleared. There is no need to maintain
- * a seperate value and test it at each iteration.
+ * a separate value and test it at each iteration.
*/
if (intRegVal & sc->lowPriorityTableFirstHalfMask) {
priorityTableIndex = 0;
diff --git a/sys/arm/xscale/ixp425/ixp425reg.h b/sys/arm/xscale/ixp425/ixp425reg.h
index f27fbb3..570dbc3 100644
--- a/sys/arm/xscale/ixp425/ixp425reg.h
+++ b/sys/arm/xscale/ixp425/ixp425reg.h
@@ -323,6 +323,8 @@
#define GPIO_TYPE(b,v) ((v) << (((b) & 0x7) * 3))
#define GPIO_TYPE_REG(b) (((b)&8)?IXP425_GPIO_GPIT2R:IXP425_GPIO_GPIT1R)
+#define IXP4XX_GPIO_PINS 16
+
/*
* Expansion Bus Configuration Space.
*/
diff --git a/sys/boot/arm/ixp425/boot2/ixp425_board.c b/sys/boot/arm/ixp425/boot2/ixp425_board.c
index 50e317d..c13f8ed 100644
--- a/sys/boot/arm/ixp425/boot2/ixp425_board.c
+++ b/sys/boot/arm/ixp425/boot2/ixp425_board.c
@@ -88,7 +88,7 @@ board_init(void)
/*
* This should be called just before starting the kernel. This is so
- * that one can undo incompatable hardware settings.
+ * that one can undo incompatible hardware settings.
*/
void
clr_board(void)
@@ -504,7 +504,7 @@ cfaltwait(u_int8_t mask)
while (tout <= 5000000) {
status = cfaltread8(CF_ALT_STATUS);
if (status == 0xff) {
- printf("cfaltwait: master: no status, reselectin\n");
+ printf("cfaltwait: master: no status, reselecting\n");
cfwrite8(CF_DRV_HEAD, CF_D_IBM);
DELAY(1);
status = cfread8(CF_STATUS);
diff --git a/sys/boot/common/loader.8 b/sys/boot/common/loader.8
index 7ccd184..56c5199 100644
--- a/sys/boot/common/loader.8
+++ b/sys/boot/common/loader.8
@@ -334,12 +334,6 @@ Some options may require a value,
while others define behavior just by being set.
Both types of builtin variables are described below.
.Bl -tag -width bootfile
-.It Va acpi_load
-Unset this to disable automatic loading of the ACPI module.
-See also
-.Va hint.acpi.0.disabled
-in
-.Xr device.hints 5 .
.It Va autoboot_delay
Number of seconds
.Ic autoboot
diff --git a/sys/boot/fdt/dts/mpc8555cds.dts b/sys/boot/fdt/dts/mpc8555cds.dts
index 4f057dc..34991ba 100644
--- a/sys/boot/fdt/dts/mpc8555cds.dts
+++ b/sys/boot/fdt/dts/mpc8555cds.dts
@@ -97,7 +97,7 @@
memory {
device_type = "memory";
- reg = <0x0 0x8000000>; // 128M at 0x0
+ reg = <0x0 0x10000000>; // 256M at 0x0
};
localbus@e0005000 {
diff --git a/sys/boot/forth/beastie.4th b/sys/boot/forth/beastie.4th
index d96f579..79b818d 100644
--- a/sys/boot/forth/beastie.4th
+++ b/sys/boot/forth/beastie.4th
@@ -141,13 +141,11 @@ at-xy ." `--{__________) "
;
: acpienabled? ( -- flag )
- s" acpi_load" getenv
+ s" hint.acpi.0.rsdp" getenv
dup -1 = if
drop false exit
then
- s" YES" compare-insensitive 0<> if
- false exit
- then
+ 2drop
s" hint.acpi.0.disabled" getenv
dup -1 <> if
s" 0" compare 0<> if
@@ -254,11 +252,9 @@ set-current
dup bootkey @ = if 0 boot then
dup bootacpikey @ = if
acpienabled? if
- s" acpi_load" unsetenv
s" 1" s" hint.acpi.0.disabled" setenv
s" 1" s" loader.acpi_disabled_by_user" setenv
else
- s" YES" s" acpi_load" setenv
s" 0" s" hint.acpi.0.disabled" setenv
then
0 boot
@@ -266,7 +262,6 @@ set-current
dup bootsafekey @ = if
s" arch-i386" environment? if
drop
- s" acpi_load" unsetenv
s" 1" s" hint.acpi.0.disabled" setenv
s" 1" s" loader.acpi_disabled_by_user" setenv
s" 1" s" hint.apic.0.disabled" setenv
diff --git a/sys/boot/i386/libi386/biosacpi.c b/sys/boot/i386/libi386/biosacpi.c
index e9e2436..f511eb7 100644
--- a/sys/boot/i386/libi386/biosacpi.c
+++ b/sys/boot/i386/libi386/biosacpi.c
@@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$");
#include "actbl.h"
/*
- * Detect ACPI and export information about the APCI BIOS into the
+ * Detect ACPI and export information about the ACPI BIOS into the
* environment.
*/
@@ -56,8 +56,6 @@ biosacpi_detect(void)
char buf[24];
int revision;
- /* XXX check the BIOS datestamp */
-
/* locate and validate the RSDP */
if ((rsdp = biosacpi_find_rsdp()) == NULL)
return;
@@ -82,9 +80,6 @@ biosacpi_detect(void)
sprintf(buf, "%d", rsdp->Length);
setenv("hint.acpi.0.xsdt_length", buf, 1);
}
- /* XXX other tables? */
-
- setenv("acpi_load", "YES", 1);
}
/*
diff --git a/sys/boot/i386/libi386/i386_module.c b/sys/boot/i386/libi386/i386_module.c
index 91993df..4ddf5b2 100644
--- a/sys/boot/i386/libi386/i386_module.c
+++ b/sys/boot/i386/libi386/i386_module.c
@@ -44,25 +44,7 @@ __FBSDID("$FreeBSD$");
int
i386_autoload(void)
{
- int error;
- int disabled;
- char *rv;
/* XXX use PnP to locate stuff here */
-
- /* autoload ACPI support */
- /* XXX should be in 4th keyed off acpi_load */
- disabled = 0;
- rv = getenv("hint.acpi.0.disabled");
- if (rv != NULL && strncmp(rv, "0", 1) != 0) {
- disabled = 1;
- }
-
- if (getenv("acpi_load") && (!disabled)) {
- error = mod_load("acpi", NULL, 0, NULL);
- if (error != 0)
- printf("ACPI autoload failed - %s\n", strerror(error));
- }
-
return(0);
}
diff --git a/sys/boot/i386/loader/help.i386 b/sys/boot/i386/loader/help.i386
index 6928c8e..dc28534 100644
--- a/sys/boot/i386/loader/help.i386
+++ b/sys/boot/i386/loader/help.i386
@@ -1,22 +1,4 @@
################################################################################
-# TACPI DControl ACPI module behaviour
-
- $acpi_load
-
- If set, the ACPI module will be loaded. Clear it with
-
- unset acpi_load
-
- $hint.acpi.0.disabled="1"
-
- If set, the ACPI module won't be loaded.
-
- Note that the ACPI autodetection sets a number of hints to
- pass information to the ACPI module. These should not be
- overridden, or system behaviour will be undefined.
-
-
-################################################################################
# Treboot DReboot the system
reboot
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
index 36a4f22..83bd075 100644
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -1055,6 +1055,7 @@ camperiphsensedone(struct cam_periph *periph, union ccb *done_ccb)
saved_ccb->ccb_h.status |=
CAM_AUTOSENSE_FAIL;
}
+ saved_ccb->csio.sense_resid = done_ccb->csio.resid;
bcopy(saved_ccb, done_ccb, sizeof(union ccb));
xpt_free_ccb(saved_ccb);
break;
@@ -1211,7 +1212,7 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
scsi_request_sense(&done_ccb->csio, /*retries*/1,
camperiphsensedone,
&save_ccb->csio.sense_data,
- sizeof(save_ccb->csio.sense_data),
+ save_ccb->csio.sense_len,
CAM_TAG_ACTION_NONE,
/*sense_len*/SSD_FULL_SIZE,
/*timeout*/5000);
@@ -1602,7 +1603,7 @@ camperiphscsisenseerror(union ccb *ccb, cam_flags camflags,
scsi_request_sense(&ccb->csio, /*retries*/1,
camperiphsensedone,
&orig_ccb->csio.sense_data,
- sizeof(orig_ccb->csio.sense_data),
+ orig_ccb->csio.sense_len,
CAM_TAG_ACTION_NONE,
/*sense_len*/SSD_FULL_SIZE,
/*timeout*/5000);
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 76c8c37..8626e66 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -276,11 +276,12 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
sbuf_printf(sb,
"processor\t: %d\n"
"vendor_id\t: %.20s\n"
- "cpu family\t: %d\n"
- "model\t\t: %d\n"
+ "cpu family\t: %u\n"
+ "model\t\t: %u\n"
"model name\t: %s\n"
- "stepping\t: %d\n\n",
- i, cpu_vendor, class, cpu, model, cpu_id & 0xf);
+ "stepping\t: %u\n\n",
+ i, cpu_vendor, CPUID_TO_FAMILY(cpu_id),
+ CPUID_TO_MODEL(cpu_id), model, cpu_id & CPUID_STEPPING);
/* XXX per-cpu vendor / class / model / id? */
}
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 04184ae..f169de5 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -2426,12 +2426,9 @@ MmAllocateContiguousMemorySpecifyCache(size, lowest, highest,
uint64_t boundary;
uint32_t cachetype;
{
- void *addr;
- size_t pagelength = roundup(size, PAGE_SIZE);
-
- addr = ExAllocatePoolWithTag(NonPagedPool, pagelength, 0);
- return (addr);
+ return (contigmalloc(size, M_DEVBUF, M_ZERO|M_NOWAIT, lowest,
+ highest, PAGE_SIZE, boundary));
}
static void
@@ -2447,7 +2444,7 @@ MmFreeContiguousMemorySpecifyCache(base, size, cachetype)
uint32_t size;
uint32_t cachetype;
{
- ExFreePool(base);
+ contigfree(base, size, M_DEVBUF);
}
static uint32_t
diff --git a/sys/conf/Makefile.mips b/sys/conf/Makefile.mips
index 6291d6c..57e1dfe 100644
--- a/sys/conf/Makefile.mips
+++ b/sys/conf/Makefile.mips
@@ -32,9 +32,6 @@ LDSCRIPT_NAME?=ldscript.$M
SYSTEM_LD:= ${SYSTEM_LD:$S/conf/${LDSCRIPT_NAME}=${LDSCRIPT_NAME}}
SYSTEM_DEP:= ${SYSTEM_DEP:$S/conf/${LDSCRIPT_NAME}=${LDSCRIPT_NAME}}
-# XXX: Such sweeping assumptions...
-MACHINE=mips
-MACHINE_ARCH=mips
KERNLOADADDR?=0x80001000
# This obscure value is defined by CFE for WR160N
# To be changed later
@@ -48,20 +45,6 @@ ARCH_FLAGS?=-march=mips32
EXTRA_FLAGS=-fno-pic -mno-abicalls -G0
HACK_EXTRA_FLAGS=-shared
-.if defined(TARGET_BIG_ENDIAN)
-CFLAGS+=-EB
-SYSTEM_LD+=-EB
-EXTRA_FLAGS+=-EB
-TRAMP_LDFLAGS+=-Wl,-EB
-HACK_EXTRA_FLAGS+=-EB -Wl,-EB
-.else
-CFLAGS+=-EL
-SYSTEM_LD+=-EL
-EXTRA_FLAGS+=-EL
-TRAMP_LDFLAGS+=-Wl,-EL
-HACK_EXTRA_FLAGS+=-EL -Wl,-EL
-.endif
-
# We add the -fno-pic flag to kernels because otherwise performance
# is extremely poor, as well as -mno-abicalls to force no ABI usage.
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index fb4bc2f..470aca5 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -67,7 +67,6 @@ hptrr_lib.o optional hptrr \
compile-with "uudecode < $S/dev/hptrr/amd64-elf.hptrr_lib.o.uu" \
no-implicit-rule
#
-amd64/acpica/OsdEnvironment.c optional acpi
amd64/acpica/acpi_machdep.c optional acpi
amd64/acpica/acpi_switch.S optional acpi
acpi_wakecode.o optional acpi \
@@ -92,7 +91,6 @@ acpi_wakedata.h optional acpi \
clean "acpi_wakedata.h"
#
amd64/acpica/acpi_wakeup.c optional acpi
-amd64/acpica/madt.c optional acpi
amd64/amd64/amd64_mem.c optional mem
#amd64/amd64/apic_vector.S standard
amd64/amd64/atomic.c standard
@@ -301,6 +299,9 @@ contrib/x86emu/x86emu.c optional x86bios | atkbd | dpms | vesa
#
# x86 shared code between IA32, AMD64 and PC98 architectures
#
+x86/acpica/OsdEnvironment.c optional acpi
+x86/acpica/acpi_apm.c optional acpi
+x86/acpica/madt.c optional acpi
x86/acpica/srat.c optional acpi
x86/bios/smbios.c optional smbios
x86/bios/vpd.c optional vpd
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index cb05bec..c955507 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -238,7 +238,6 @@ dev/uart/uart_cpu_i386.c optional uart
dev/acpica/acpi_if.m standard
dev/acpi_support/acpi_wmi_if.m standard
dev/wpi/if_wpi.c optional wpi
-i386/acpica/OsdEnvironment.c optional acpi
i386/acpica/acpi_machdep.c optional acpi
i386/acpica/acpi_wakeup.c optional acpi
acpi_wakecode.h optional acpi \
@@ -247,7 +246,6 @@ acpi_wakecode.h optional acpi \
no-obj no-implicit-rule before-depend \
clean "acpi_wakecode.h acpi_wakecode.o acpi_wakecode.bin"
#
-i386/acpica/madt.c optional acpi apic
i386/bios/apm.c optional apm
i386/bios/mca_machdep.c optional mca
i386/bios/smapi.c optional smapi
@@ -374,6 +372,9 @@ compat/x86bios/x86bios.c optional x86bios | atkbd | dpms | vesa
#
# x86 shared code between IA32, AMD64 and PC98 architectures
#
+x86/acpica/OsdEnvironment.c optional acpi
+x86/acpica/acpi_apm.c optional acpi
+x86/acpica/madt.c optional acpi apic
x86/acpica/srat.c optional acpi
x86/bios/smbios.c optional smbios
x86/bios/vpd.c optional vpd
diff --git a/sys/conf/files.mips b/sys/conf/files.mips
index 99a7723..61a9295 100644
--- a/sys/conf/files.mips
+++ b/sys/conf/files.mips
@@ -55,6 +55,7 @@ mips/mips/db_trace.c optional ddb
mips/mips/dump_machdep.c standard
mips/mips/in_cksum.c optional inet
mips/mips/locore.S standard no-obj
+mips/mips/minidump_machdep.c standard
mips/mips/mem.c optional mem
mips/mips/nexus.c standard
mips/mips/stack_machdep.c optional ddb | stack
diff --git a/sys/contrib/octeon-sdk/cvmx-app-init.h b/sys/contrib/octeon-sdk/cvmx-app-init.h
index 8f768ed..8b43bcf 100644
--- a/sys/contrib/octeon-sdk/cvmx-app-init.h
+++ b/sys/contrib/octeon-sdk/cvmx-app-init.h
@@ -193,6 +193,9 @@ enum cvmx_board_types_enum {
CVMX_BOARD_TYPE_CUST_GCT108 = 10012,
CVMX_BOARD_TYPE_CUST_AGS109 = 10013,
CVMX_BOARD_TYPE_CUST_GCT110 = 10014,
+#if defined(OCTEON_VENDOR_LANNER)
+ CVMX_BOARD_TYPE_CUST_LANNER_MR730= 10021,
+#endif
CVMX_BOARD_TYPE_CUST_DEFINED_MAX = 20000,
/* Set aside a range for customer private use. The SDK won't
@@ -272,6 +275,9 @@ static inline const char *cvmx_board_type_to_string(enum cvmx_board_types_enum t
ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_GCT108)
ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_AGS109)
ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_GCT110)
+#if defined(OCTEON_VENDOR_LANNER)
+ ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_LANNER_MR730)
+#endif
ENUM_BRD_TYPE_CASE(CVMX_BOARD_TYPE_CUST_DEFINED_MAX)
/* Customer private range */
diff --git a/sys/contrib/octeon-sdk/cvmx-helper-board.c b/sys/contrib/octeon-sdk/cvmx-helper-board.c
index cca2b22..4efc825 100644
--- a/sys/contrib/octeon-sdk/cvmx-helper-board.c
+++ b/sys/contrib/octeon-sdk/cvmx-helper-board.c
@@ -114,9 +114,6 @@ int cvmx_helper_board_get_mii_address(int ipd_port)
case CVMX_BOARD_TYPE_EBT5800:
case CVMX_BOARD_TYPE_THUNDER:
case CVMX_BOARD_TYPE_NICPRO2:
-#if defined(OCTEON_VENDOR_LANNER)
- case CVMX_BOARD_TYPE_CUST_LANNER_MR955:
-#endif
/* Interface 0 is SPI4, interface 1 is RGMII */
if ((ipd_port >= 16) && (ipd_port < 20))
return ipd_port - 16;
@@ -180,6 +177,15 @@ int cvmx_helper_board_get_mii_address(int ipd_port)
/* Private vendor-defined boards. */
#if defined(OCTEON_VENDOR_LANNER)
+ case CVMX_BOARD_TYPE_CUST_LANNER_MR955:
+ /* Interface 1 is 12 BCM5482S PHYs. */
+ if ((ipd_port >= 16) && (ipd_port < 28))
+ return ipd_port - 16;
+ return -1;
+ case CVMX_BOARD_TYPE_CUST_LANNER_MR730:
+ if ((ipd_port >= 0) && (ipd_port < 4))
+ return ipd_port;
+ return -1;
case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
/* Port 0 is a Marvell 88E6161 switch, ports 1 and 2 are Marvell
88E1111 interfaces. */
@@ -291,6 +297,10 @@ cvmx_helper_link_info_t __cvmx_helper_board_link_get(int ipd_port)
break;
/* Private vendor-defined boards. */
#if defined(OCTEON_VENDOR_LANNER)
+ case CVMX_BOARD_TYPE_CUST_LANNER_MR730:
+ /* Ports are BCM5482S */
+ is_broadcom_phy = 1;
+ break;
case CVMX_BOARD_TYPE_CUST_LANNER_MR320:
/* Port 0 connects to the switch */
if (ipd_port == 0)
diff --git a/sys/contrib/octeon-sdk/cvmx-helper.c b/sys/contrib/octeon-sdk/cvmx-helper.c
index cd155bb..fbb1316 100644
--- a/sys/contrib/octeon-sdk/cvmx-helper.c
+++ b/sys/contrib/octeon-sdk/cvmx-helper.c
@@ -105,6 +105,8 @@ int cvmx_helper_get_number_of_interfaces(void)
#if defined(OCTEON_VENDOR_LANNER)
case CVMX_BOARD_TYPE_CUST_LANNER_MR955:
return 2;
+ case CVMX_BOARD_TYPE_CUST_LANNER_MR730:
+ return 1;
#endif
default:
break;
diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index 500a072..c7460ef 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -1693,7 +1693,7 @@ acpi_probe_child(ACPI_HANDLE handle, UINT32 level, void *context, void **status)
/*
* Since we scan from \, be sure to skip system scope objects.
* \_SB_ and \_TZ_ are defined in ACPICA as devices to work around
- * BIOS bugs. For example, \_SB_ is to allow \_SB._INI to be run
+ * BIOS bugs. For example, \_SB_ is to allow \_SB_._INI to be run
* during the intialization and \_TZ_ is to support Notify() on it.
*/
if (strcmp(handle_str, "\\_SB_") == 0 ||
diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h
index 34284d5..5d5f9ca 100644
--- a/sys/dev/acpica/acpivar.h
+++ b/sys/dev/acpica/acpivar.h
@@ -396,6 +396,9 @@ ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE consumer, int state);
int acpi_device_pwr_for_sleep(device_t bus, device_t dev,
int *dstate);
+/* APM emulation */
+void acpi_apm_init(struct acpi_softc *);
+
/* Misc. */
static __inline struct acpi_softc *
acpi_device_get_parent_softc(device_t child)
diff --git a/sys/dev/ahci/ahci.c b/sys/dev/ahci/ahci.c
index 314bd91..6794f45 100644
--- a/sys/dev/ahci/ahci.c
+++ b/sys/dev/ahci/ahci.c
@@ -1625,12 +1625,13 @@ ahci_execute_transaction(struct ahci_slot *slot)
/* Setup the command list entry */
clp = (struct ahci_cmd_list *)
(ch->dma.work + AHCI_CL_OFFSET + (AHCI_CL_SIZE * slot->slot));
- clp->prd_length = slot->dma.nsegs;
- clp->cmd_flags = (ccb->ccb_h.flags & CAM_DIR_OUT ? AHCI_CMD_WRITE : 0) |
- (ccb->ccb_h.func_code == XPT_SCSI_IO ?
- (AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH) : 0) |
- (fis_size / sizeof(u_int32_t)) |
- (port << 12);
+ clp->cmd_flags = htole16(
+ (ccb->ccb_h.flags & CAM_DIR_OUT ? AHCI_CMD_WRITE : 0) |
+ (ccb->ccb_h.func_code == XPT_SCSI_IO ?
+ (AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH) : 0) |
+ (fis_size / sizeof(u_int32_t)) |
+ (port << 12));
+ clp->prd_length = htole16(slot->dma.nsegs);
/* Special handling for Soft Reset command. */
if ((ccb->ccb_h.func_code == XPT_ATA_IO) &&
(ccb->ataio.cmd.flags & CAM_ATAIO_CONTROL)) {
@@ -1650,7 +1651,7 @@ ahci_execute_transaction(struct ahci_slot *slot)
clp->cmd_table_phys = htole64(ch->dma.work_bus + AHCI_CT_OFFSET +
(AHCI_CT_SIZE * slot->slot));
bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
- BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
bus_dmamap_sync(ch->dma.rfis_tag, ch->dma.rfis_map,
BUS_DMASYNC_PREREAD);
/* Set ACTIVE bit for NCQ commands. */
@@ -1855,10 +1856,13 @@ ahci_end_transaction(struct ahci_slot *slot, enum ahci_err_type et)
device_t dev = slot->dev;
struct ahci_channel *ch = device_get_softc(dev);
union ccb *ccb = slot->ccb;
+ struct ahci_cmd_list *clp;
int lastto;
bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map,
- BUS_DMASYNC_POSTWRITE);
+ BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
+ clp = (struct ahci_cmd_list *)
+ (ch->dma.work + AHCI_CL_OFFSET + (AHCI_CL_SIZE * slot->slot));
/* Read result registers to the result struct
* May be incorrect if several commands finished same time,
* so read only when sure or have to.
@@ -1893,6 +1897,16 @@ ahci_end_transaction(struct ahci_slot *slot, enum ahci_err_type et)
res->sector_count_exp = fis[13];
} else
bzero(res, sizeof(*res));
+ if ((ccb->ataio.cmd.flags & CAM_ATAIO_FPDMA) == 0 &&
+ (ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
+ ccb->ataio.resid =
+ ccb->ataio.dxfer_len - le32toh(clp->bytecount);
+ }
+ } else {
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
+ ccb->csio.resid =
+ ccb->csio.dxfer_len - le32toh(clp->bytecount);
+ }
}
if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c
index f40dcc2..c7fe9ba 100644
--- a/sys/dev/ata/ata-all.c
+++ b/sys/dev/ata/ata-all.c
@@ -1517,6 +1517,15 @@ ata_cam_end_transaction(device_t dev, struct ata_request *request)
res->sector_count = request->u.ata.count;
res->sector_count_exp = request->u.ata.count >> 8;
}
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
+ if (ccb->ccb_h.func_code == XPT_ATA_IO) {
+ ccb->ataio.resid =
+ ccb->ataio.dxfer_len - request->donecount;
+ } else {
+ ccb->csio.resid =
+ ccb->csio.dxfer_len - request->donecount;
+ }
+ }
ata_free_request(request);
xpt_done(ccb);
/* Do error recovery if needed. */
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c
index 67e092e..85b6a54 100644
--- a/sys/dev/ata/ata-disk.c
+++ b/sys/dev/ata/ata-disk.c
@@ -188,13 +188,13 @@ ad_detach(device_t dev)
free(children, M_TEMP);
}
- /* detroy disk from the system so we dont get any further requests */
+ /* destroy disk from the system so we don't get any further requests */
disk_destroy(adp->disk);
- /* fail requests on the queue and any thats "in flight" for this device */
+ /* fail requests on the queue and any that's "in flight" for this device */
ata_fail_requests(dev);
- /* dont leave anything behind */
+ /* don't leave anything behind */
device_set_ivars(dev, NULL);
free(adp, M_AD);
return 0;
@@ -536,7 +536,7 @@ ad_describe(device_t dev)
struct ad_softc *adp = device_get_ivars(dev);
u_int8_t *marker, vendor[64], product[64];
- /* try to seperate the ATA model string into vendor and model parts */
+ /* try to separate the ATA model string into vendor and model parts */
if ((marker = index(atadev->param.model, ' ')) ||
(marker = index(atadev->param.model, '-'))) {
int len = (marker - atadev->param.model);
diff --git a/sys/dev/ata/ata-lowlevel.c b/sys/dev/ata/ata-lowlevel.c
index 3ef31cf..2234efb 100644
--- a/sys/dev/ata/ata-lowlevel.c
+++ b/sys/dev/ata/ata-lowlevel.c
@@ -672,7 +672,8 @@ ata_generic_command(struct ata_request *request)
/* ready to issue command ? */
if (ata_wait(ch, request->unit, 0) < 0) {
device_printf(request->parent, "timeout waiting to issue command\n");
- return -1;
+ request->flags |= ATA_R_TIMEOUT;
+ return (-1);
}
/* enable interrupt */
@@ -697,13 +698,16 @@ ata_generic_command(struct ata_request *request)
/* command interrupt device ? just return and wait for interrupt */
if (request->flags & ATA_R_ATAPI_INTR)
- return 0;
+ return (0);
/* command processed ? */
res = ata_wait(ch, request->unit, 0);
if (res != 0) {
- if (res < 0)
- device_printf(request->parent, "timeout waiting for PACKET command\n");
+ if (res < 0) {
+ device_printf(request->parent,
+ "timeout waiting for PACKET command\n");
+ request->flags |= ATA_R_TIMEOUT;
+ }
return (-1);
}
/* wait for ready to write ATAPI command block */
@@ -717,9 +721,10 @@ ata_generic_command(struct ata_request *request)
DELAY(20);
}
if (timeout <= 0) {
- device_printf(request->parent, "timeout waiting for ATAPI ready\n");
- request->result = EIO;
- return -1;
+ device_printf(request->parent,
+ "timeout waiting for ATAPI ready\n");
+ request->flags |= ATA_R_TIMEOUT;
+ return (-1);
}
/* this seems to be needed for some (slow) devices */
@@ -735,7 +740,7 @@ ata_generic_command(struct ata_request *request)
/* issue command to controller */
ATA_IDX_OUTB(ch, ATA_COMMAND, request->u.ata.command);
}
- return 0;
+ return (0);
}
static void
diff --git a/sys/dev/drm/r300_reg.h b/sys/dev/drm/r300_reg.h
index 928440f..8a13c31 100644
--- a/sys/dev/drm/r300_reg.h
+++ b/sys/dev/drm/r300_reg.h
@@ -345,7 +345,7 @@ __FBSDID("$FreeBSD$");
* position takes place.
*
* Most likely this is used to ignore rest of the program in cases
- * where group of verts arent visible. For some reason this "section"
+ * where group of verts aren't visible. For some reason this "section"
* is sometimes accepted other instruction that have no relationship with
* position calculations.
*/
@@ -590,7 +590,7 @@ __FBSDID("$FreeBSD$");
#define R300_RE_FOG_START 0x4298
/* Not sure why there are duplicate of factor and constant values.
- * My best guess so far is that there are seperate zbiases for test and write.
+ * My best guess so far is that there are separate zbiases for test and write.
* Ordering might be wrong.
* Some of the tests indicate that fgl has a fallback implementation of zbias
* via pixel shaders.
@@ -608,7 +608,7 @@ __FBSDID("$FreeBSD$");
* My guess is that there are two bits for each zbias primitive
* (FILL, LINE, POINT).
* One to enable depth test and one for depth write.
- * Yet this doesnt explain why depth writes work ...
+ * Yet this doesn't explain why depth writes work ...
*/
#define R300_RE_OCCLUSION_CNTL 0x42B4
# define R300_OCCLUSION_ON (1<<1)
@@ -693,7 +693,7 @@ __FBSDID("$FreeBSD$");
* the ROUTE_0_COLOR bit is set and ROUTE_0_COLOR_DEST contains the
* color register index.
*
- * Apperently you may set the R300_RS_ROUTE_0_COLOR bit, but not provide any
+ * Apparently you may set the R300_RS_ROUTE_0_COLOR bit, but not provide any
* R300_RS_ROUTE_0_COLOR_DEST value; this setup is used for clearing the state.
* See r300_ioctl.c:r300EmitClearState. I'm not sure if this setup is strictly
* correct or not. - Oliver.
@@ -817,8 +817,8 @@ __FBSDID("$FreeBSD$");
# define R300_TX_MIN_FILTER_LINEAR_MIP_NEAREST (6 << 11)
# define R300_TX_MIN_FILTER_LINEAR_MIP_LINEAR (10 << 11)
-/* NOTE: NEAREST doesnt seem to exist.
- * Im not seting MAG_FILTER_MASK and (3 << 11) on for all
+/* NOTE: NEAREST doesn't seem to exist.
+ * I'm not setting MAG_FILTER_MASK and (3 << 11) on for all
* anisotropy modes because that would void selected mag filter
*/
# define R300_TX_MIN_FILTER_ANISO_NEAREST (0 << 13)
diff --git a/sys/dev/gpio/gpioled.c b/sys/dev/gpio/gpioled.c
index d96b8b7..a03c172 100644
--- a/sys/dev/gpio/gpioled.c
+++ b/sys/dev/gpio/gpioled.c
@@ -103,6 +103,9 @@ gpioled_attach(device_t dev)
device_get_unit(dev), "name", &name))
name = NULL;
+ GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN,
+ GPIO_PIN_OUTPUT);
+
sc->sc_leddev = led_create(gpioled_control, sc, name ? name :
device_get_nameunit(dev));
diff --git a/sys/dev/iicbus/iiconf.c b/sys/dev/iicbus/iiconf.c
index 1610b35..e59dc35 100644
--- a/sys/dev/iicbus/iiconf.c
+++ b/sys/dev/iicbus/iiconf.c
@@ -363,7 +363,7 @@ iicbus_transfer(device_t bus, struct iic_msg *msgs, uint32_t nmsgs)
int
iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
{
- int i, error, lenread, lenwrote, nkid;
+ int i, error, lenread, lenwrote, nkid, rpstart, addr;
device_t *children, bus;
if ((error = device_get_children(dev, &children, &nkid)) != 0)
@@ -373,14 +373,38 @@ iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
return (EIO);
}
bus = children[0];
+ rpstart = 0;
free(children, M_TEMP);
for (i = 0, error = 0; i < nmsgs && error == 0; i++) {
+ addr = msgs[i].slave;
if (msgs[i].flags & IIC_M_RD)
- error = iicbus_block_read(bus, msgs[i].slave,
- msgs[i].buf, msgs[i].len, &lenread);
+ addr |= LSB;
else
- error = iicbus_block_write(bus, msgs[i].slave,
- msgs[i].buf, msgs[i].len, &lenwrote);
+ addr &= ~LSB;
+
+ if (!(msgs[i].flags & IIC_M_NOSTART)) {
+ if (rpstart)
+ error = iicbus_repeated_start(bus, addr, 0);
+ else
+ error = iicbus_start(bus, addr, 0);
+ }
+
+ if (error)
+ break;
+
+ if (msgs[i].flags & IIC_M_RD)
+ error = iicbus_read(bus, msgs[i].buf, msgs[i].len,
+ &lenread, IIC_LAST_READ, 0);
+ else
+ error = iicbus_write(bus, msgs[i].buf, msgs[i].len,
+ &lenwrote, 0);
+
+ if (!(msgs[i].flags & IIC_M_NOSTOP)) {
+ rpstart = 0;
+ iicbus_stop(bus);
+ } else {
+ rpstart = 1; /* Next message gets repeated start */
+ }
}
return (error);
}
diff --git a/sys/dev/isp/isp_freebsd.c b/sys/dev/isp/isp_freebsd.c
index 1e34cfb..6de0e5d 100644
--- a/sys/dev/isp/isp_freebsd.c
+++ b/sys/dev/isp/isp_freebsd.c
@@ -1790,7 +1790,7 @@ isp_handle_platform_atio(ispsoftc_t *isp, at_entry_t *aep)
* The firmware status (except for the QLTM_SVALID bit)
* indicates why this ATIO was sent to us.
*
- * If QLTM_SVALID is set, the firware has recommended Sense Data.
+ * If QLTM_SVALID is set, the firmware has recommended Sense Data.
*
* If the DISCONNECTS DISABLED bit is set in the flags field,
* we're still connected on the SCSI bus.
@@ -1917,7 +1917,7 @@ isp_handle_platform_atio2(ispsoftc_t *isp, at2_entry_t *aep)
* The firmware status (except for the QLTM_SVALID bit)
* indicates why this ATIO was sent to us.
*
- * If QLTM_SVALID is set, the firware has recommended Sense Data.
+ * If QLTM_SVALID is set, the firmware has recommended Sense Data.
*/
if ((aep->at_status & ~QLTM_SVALID) != AT_CDB) {
isp_prt(isp, ISP_LOGWARN, "bogus atio (0x%x) leaked to platform", aep->at_status);
@@ -2581,7 +2581,7 @@ isp_handle_platform_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot)
/*
* Note that we're just getting notification that an ELS was received
- * (possibly with some associcated information sent upstream). This is
+ * (possibly with some associated information sent upstream). This is
* *not* the same as being given the ELS frame to accept or reject.
*/
switch (inot->in_status_subcode) {
@@ -2784,7 +2784,7 @@ isp_handle_platform_target_notify_ack(ispsoftc_t *isp, isp_notify_t *mp)
}
/*
- * Handle task managment functions.
+ * Handle task management functions.
*
* We show up here with a notify structure filled out.
*
@@ -2894,7 +2894,7 @@ bad:
}
/*
- * Find the associated private data and makr it as dead so
+ * Find the associated private data and mark it as dead so
* we don't try to work on it any further.
*/
static void
@@ -5368,7 +5368,7 @@ isp_default_wwn(ispsoftc_t * isp, int chan, int isactive, int iswwnn)
/*
- * For channel zero just return what we have. For either ACIIVE or
+ * For channel zero just return what we have. For either ACTIVE or
* DEFAULT cases, we depend on default override of NVRAM values for
* channel zero.
*/
@@ -5404,7 +5404,7 @@ isp_default_wwn(ispsoftc_t * isp, int chan, int isactive, int iswwnn)
* physical port on dual-port chips (23XX/24XX)
*
* This is somewhat nutty, particularly since bit 48 is
- * irrelevant as they assign seperate serial numbers to
+ * irrelevant as they assign separate serial numbers to
* different physical ports anyway.
*
* We'll stick our channel number plus one first into bits
diff --git a/sys/dev/ixgbe/ixgbe.c b/sys/dev/ixgbe/ixgbe.c
index 37b98df..f9605e5 100644
--- a/sys/dev/ixgbe/ixgbe.c
+++ b/sys/dev/ixgbe/ixgbe.c
@@ -257,7 +257,7 @@ TUNABLE_INT("hw.ixgbe.enable_msix", &ixgbe_enable_msix);
/*
* Header split: this causes the hardware to DMA
- * the header into a seperate mbuf from the payload,
+ * the header into a separate mbuf from the payload,
* it can be a performance win in some workloads, but
* in others it actually hurts, its off by default.
*/
@@ -3661,7 +3661,7 @@ ixgbe_setup_receive_ring(struct rx_ring *rxr)
rxbuf = &rxr->rx_buffers[j];
/*
- ** Dont allocate mbufs if not
+ ** Don't allocate mbufs if not
** doing header split, its wasteful
*/
if (rxr->hdr_split == FALSE)
@@ -4129,7 +4129,7 @@ ixgbe_rxeof(struct ix_queue *que, int count)
** not be fragmented across sequential
** descriptors, rather the next descriptor
** is indicated in bits of the descriptor.
- ** This also means that we might proceses
+ ** This also means that we might process
** more than one packet at a time, something
** that has never been true before, it
** required eliminating global chain pointers
@@ -4478,14 +4478,14 @@ ixgbe_enable_intr(struct adapter *adapter)
/* With RSS we use auto clear */
if (adapter->msix_mem) {
mask = IXGBE_EIMS_ENABLE_MASK;
- /* Dont autoclear Link */
+ /* Don't autoclear Link */
mask &= ~IXGBE_EIMS_OTHER;
mask &= ~IXGBE_EIMS_LSC;
IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
}
/*
- ** Now enable all queues, this is done seperately to
+ ** Now enable all queues, this is done separately to
** allow for handling the extended (beyond 32) MSIX
** vectors that can be used by 82599
*/
diff --git a/sys/dev/mii/brgphy.c b/sys/dev/mii/brgphy.c
index 454ee22..62fcd8f 100644
--- a/sys/dev/mii/brgphy.c
+++ b/sys/dev/mii/brgphy.c
@@ -132,6 +132,7 @@ static const struct mii_phydesc brgphys[] = {
MII_PHY_DESC(xxBROADCOM, BCM5754),
MII_PHY_DESC(xxBROADCOM, BCM5780),
MII_PHY_DESC(xxBROADCOM, BCM5708C),
+ MII_PHY_DESC(xxBROADCOM_ALT1, BCM5482S),
MII_PHY_DESC(xxBROADCOM_ALT1, BCM5755),
MII_PHY_DESC(xxBROADCOM_ALT1, BCM5787),
MII_PHY_DESC(xxBROADCOM_ALT1, BCM5708S),
diff --git a/sys/dev/mii/miidevs b/sys/dev/mii/miidevs
index 34c5f94..ec0b846 100644
--- a/sys/dev/mii/miidevs
+++ b/sys/dev/mii/miidevs
@@ -145,6 +145,7 @@ model xxBROADCOM BCM54K2 0x002e BCM54K2 10/100/1000baseTX PHY
model xxBROADCOM BCM5714 0x0034 BCM5714 10/100/1000baseTX PHY
model xxBROADCOM BCM5780 0x0035 BCM5780 10/100/1000baseTX PHY
model xxBROADCOM BCM5708C 0x0036 BCM5708C 10/100/1000baseTX PHY
+model xxBROADCOM_ALT1 BCM5482S 0x000b BCM5482S Dual-Port 10/100/1000baseX/FX PHY
model xxBROADCOM_ALT1 BCM5755 0x000c BCM5755 10/100/1000baseTX PHY
model xxBROADCOM_ALT1 BCM5787 0x000e BCM5787 10/100/1000baseTX PHY
model xxBROADCOM_ALT1 BCM5708S 0x0015 BCM5708S 1000/2500BaseSX PHY
diff --git a/sys/dev/msk/if_msk.c b/sys/dev/msk/if_msk.c
index 4c144fd..8eb2ffa 100644
--- a/sys/dev/msk/if_msk.c
+++ b/sys/dev/msk/if_msk.c
@@ -1157,7 +1157,7 @@ mskc_setup_rambuffer(struct msk_softc *sc)
sc->msk_pflags |= MSK_FLAG_RAMBUF;
/*
* Give receiver 2/3 of memory and round down to the multiple
- * of 1024. Tx/Rx RAM buffer size of Yukon II shoud be multiple
+ * of 1024. Tx/Rx RAM buffer size of Yukon II should be multiple
* of 1024.
*/
sc->msk_rxqsize = rounddown((sc->msk_ramsize * 1024 * 2) / 3, 1024);
@@ -1621,7 +1621,7 @@ msk_attach(device_t dev)
*/
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWTSO;
/*
- * Enable Rx checksum offloading for VLAN taggedd frames
+ * Enable Rx checksum offloading for VLAN tagged frames
* if controller support new descriptor format.
*/
if ((sc_if->msk_flags & MSK_FLAG_DESCV2) != 0 &&
@@ -1809,7 +1809,7 @@ mskc_attach(device_t dev)
* does not rely on status word of received frame
* in msk_rxeof() which in turn disables all
* hardware assistance bits reported by the status
- * word as well as validity of the recevied frame.
+ * word as well as validity of the received frame.
* Just pass received frames to upper stack with
* minimal test and let upper stack handle them.
*/
@@ -2143,10 +2143,10 @@ msk_txrx_dma_alloc(struct msk_if_softc *sc_if)
* what DMA address is used and chain another descriptor for the
* 64bits DMA operation. This also means descriptor ring size is
* variable. Limiting DMA address to be in 32bit address space greatly
- * simplyfies descriptor handling and possibly would increase
+ * simplifies descriptor handling and possibly would increase
* performance a bit due to efficient handling of descriptors.
* Apart from harassing checksum offloading mechanisms, it seems
- * it's really bad idea to use a seperate descriptor for 64bit
+ * it's really bad idea to use a separate descriptor for 64bit
* DMA operation to save small descriptor memory. Anyway, I've
* never seen these exotic scheme on ethernet interface hardware.
*/
@@ -2643,7 +2643,7 @@ msk_encap(struct msk_if_softc *sc_if, struct mbuf **m_head)
* Short UDP packets appear to be handled correctly by
* Yukon II. Also I assume this bug does not happen on
* controllers that use newer descriptor format or
- * automatic Tx checksum calaulcation.
+ * automatic Tx checksum calculation.
*/
m = m_pullup(m, offset + sizeof(struct tcphdr));
if (m == NULL) {
@@ -2780,7 +2780,7 @@ msk_encap(struct msk_if_softc *sc_if, struct mbuf **m_head)
/* Update producer index. */
sc_if->msk_cdata.msk_tx_prod = prod;
- /* Set EOP on the last desciptor. */
+ /* Set EOP on the last descriptor. */
prod = (prod + MSK_TX_RING_CNT - 1) % MSK_TX_RING_CNT;
tx_le = &sc_if->msk_rdata.msk_tx_ring[prod];
tx_le->msk_control |= htole32(EOP);
@@ -3321,7 +3321,7 @@ msk_intr_gmac(struct msk_if_softc *sc_if)
* XXX
* In case of Tx underrun, we may need to flush/reset
* Tx MAC but that would also require resynchronization
- * with status LEs. Reintializing status LEs would
+ * with status LEs. Reinitializing status LEs would
* affect other port in dual MAC configuration so it
* should be avoided as possible as we can.
* Due to lack of documentation it's all vague guess but
@@ -3833,7 +3833,7 @@ msk_init_locked(struct msk_if_softc *sc_if)
msk_setvlan(sc_if, ifp);
if ((sc_if->msk_flags & MSK_FLAG_RAMBUF) == 0) {
- /* Set Rx Pause threshould. */
+ /* Set Rx Pause threshold. */
CSR_WRITE_2(sc, MR_ADDR(sc_if->msk_port, RX_GMF_LP_THR),
MSK_ECU_LLPP);
CSR_WRITE_2(sc, MR_ADDR(sc_if->msk_port, RX_GMF_UP_THR),
diff --git a/sys/dev/nfe/if_nfe.c b/sys/dev/nfe/if_nfe.c
index bb4f3bc..7b9b553 100644
--- a/sys/dev/nfe/if_nfe.c
+++ b/sys/dev/nfe/if_nfe.c
@@ -81,7 +81,7 @@ static void nfe_power(struct nfe_softc *);
static int nfe_miibus_readreg(device_t, int, int);
static int nfe_miibus_writereg(device_t, int, int, int);
static void nfe_miibus_statchg(device_t);
-static void nfe_link_task(void *, int);
+static void nfe_mac_config(struct nfe_softc *, struct mii_data *);
static void nfe_set_intr(struct nfe_softc *);
static __inline void nfe_enable_intr(struct nfe_softc *);
static __inline void nfe_disable_intr(struct nfe_softc *);
@@ -125,6 +125,8 @@ static int sysctl_hw_nfe_proc_limit(SYSCTL_HANDLER_ARGS);
static void nfe_sysctl_node(struct nfe_softc *);
static void nfe_stats_clear(struct nfe_softc *);
static void nfe_stats_update(struct nfe_softc *);
+static void nfe_set_linkspeed(struct nfe_softc *);
+static void nfe_set_wol(struct nfe_softc *);
#ifdef NFE_DEBUG
static int nfedebug = 0;
@@ -348,7 +350,6 @@ nfe_attach(device_t dev)
mtx_init(&sc->nfe_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF);
callout_init_mtx(&sc->nfe_stat_ch, &sc->nfe_mtx, 0);
- TASK_INIT(&sc->nfe_link_task, 0, nfe_link_task, sc);
pci_enable_busmaster(dev);
@@ -586,6 +587,9 @@ nfe_attach(device_t dev)
if ((ifp->if_capabilities & IFCAP_HWCSUM) != 0)
ifp->if_capabilities |= IFCAP_VLAN_HWCSUM;
}
+
+ if (pci_find_extcap(dev, PCIY_PMG, &reg) == 0)
+ ifp->if_capabilities |= IFCAP_WOL_MAGIC;
ifp->if_capenable = ifp->if_capabilities;
/*
@@ -666,7 +670,6 @@ nfe_detach(device_t dev)
NFE_UNLOCK(sc);
callout_drain(&sc->nfe_stat_ch);
taskqueue_drain(taskqueue_fast, &sc->nfe_tx_task);
- taskqueue_drain(taskqueue_swi, &sc->nfe_link_task);
ether_ifdetach(ifp);
}
@@ -752,6 +755,7 @@ nfe_suspend(device_t dev)
NFE_LOCK(sc);
nfe_stop(sc->nfe_ifp);
+ nfe_set_wol(sc);
sc->nfe_suspended = 1;
NFE_UNLOCK(sc);
@@ -768,6 +772,7 @@ nfe_resume(device_t dev)
sc = device_get_softc(dev);
NFE_LOCK(sc);
+ nfe_power(sc);
ifp = sc->nfe_ifp;
if (ifp->if_flags & IFF_UP)
nfe_init_locked(sc);
@@ -806,37 +811,55 @@ static void
nfe_miibus_statchg(device_t dev)
{
struct nfe_softc *sc;
-
- sc = device_get_softc(dev);
- taskqueue_enqueue(taskqueue_swi, &sc->nfe_link_task);
-}
-
-
-static void
-nfe_link_task(void *arg, int pending)
-{
- struct nfe_softc *sc;
struct mii_data *mii;
struct ifnet *ifp;
- uint32_t phy, seed, misc = NFE_MISC1_MAGIC, link = NFE_MEDIA_SET;
- uint32_t gmask, rxctl, txctl, val;
+ uint32_t rxctl, txctl;
- sc = (struct nfe_softc *)arg;
+ sc = device_get_softc(dev);
NFE_LOCK(sc);
mii = device_get_softc(sc->nfe_miibus);
ifp = sc->nfe_ifp;
- if (mii == NULL || ifp == NULL) {
- NFE_UNLOCK(sc);
- return;
- }
- if (mii->mii_media_status & IFM_ACTIVE) {
- if (IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)
+ sc->nfe_link = 0;
+ if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
+ (IFM_ACTIVE | IFM_AVALID)) {
+ switch (IFM_SUBTYPE(mii->mii_media_active)) {
+ case IFM_10_T:
+ case IFM_100_TX:
+ case IFM_1000_T:
sc->nfe_link = 1;
- } else
- sc->nfe_link = 0;
+ break;
+ default:
+ break;
+ }
+ }
+
+ nfe_mac_config(sc, mii);
+ txctl = NFE_READ(sc, NFE_TX_CTL);
+ rxctl = NFE_READ(sc, NFE_RX_CTL);
+ if (sc->nfe_link != 0 && (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
+ txctl |= NFE_TX_START;
+ rxctl |= NFE_RX_START;
+ } else {
+ txctl &= ~NFE_TX_START;
+ rxctl &= ~NFE_RX_START;
+ }
+ NFE_WRITE(sc, NFE_TX_CTL, txctl);
+ NFE_WRITE(sc, NFE_RX_CTL, rxctl);
+
+ NFE_UNLOCK(sc);
+}
+
+
+static void
+nfe_mac_config(struct nfe_softc *sc, struct mii_data *mii)
+{
+ uint32_t link, misc, phy, seed;
+ uint32_t val;
+
+ NFE_LOCK_ASSERT(sc);
phy = NFE_READ(sc, NFE_PHY_IFACE);
phy &= ~(NFE_PHY_HDX | NFE_PHY_100TX | NFE_PHY_1000T);
@@ -844,7 +867,10 @@ nfe_link_task(void *arg, int pending)
seed = NFE_READ(sc, NFE_RNDSEED);
seed &= ~NFE_SEED_MASK;
- if (((mii->mii_media_active & IFM_GMASK) & IFM_FDX) == 0) {
+ misc = NFE_MISC1_MAGIC;
+ link = NFE_MEDIA_SET;
+
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) == 0) {
phy |= NFE_PHY_HDX; /* half-duplex */
misc |= NFE_MISC1_HDX;
}
@@ -881,18 +907,18 @@ nfe_link_task(void *arg, int pending)
NFE_WRITE(sc, NFE_MISC1, misc);
NFE_WRITE(sc, NFE_LINKSPEED, link);
- gmask = mii->mii_media_active & IFM_GMASK;
- if ((gmask & IFM_FDX) != 0) {
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) {
/* It seems all hardwares supports Rx pause frames. */
val = NFE_READ(sc, NFE_RXFILTER);
- if ((gmask & IFM_FLAG0) != 0)
+ if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FLAG0) != 0)
val |= NFE_PFF_RX_PAUSE;
else
val &= ~NFE_PFF_RX_PAUSE;
NFE_WRITE(sc, NFE_RXFILTER, val);
if ((sc->nfe_flags & NFE_TX_FLOW_CTRL) != 0) {
val = NFE_READ(sc, NFE_MISC1);
- if ((gmask & IFM_FLAG1) != 0) {
+ if ((IFM_OPTIONS(mii->mii_media_active) &
+ IFM_FLAG1) != 0) {
NFE_WRITE(sc, NFE_TX_PAUSE_FRAME,
NFE_TX_PAUSE_FRAME_ENABLE);
val |= NFE_MISC1_TX_PAUSE;
@@ -916,20 +942,6 @@ nfe_link_task(void *arg, int pending)
NFE_WRITE(sc, NFE_MISC1, val);
}
}
-
- txctl = NFE_READ(sc, NFE_TX_CTL);
- rxctl = NFE_READ(sc, NFE_RX_CTL);
- if (sc->nfe_link != 0 && (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
- txctl |= NFE_TX_START;
- rxctl |= NFE_RX_START;
- } else {
- txctl &= ~NFE_TX_START;
- rxctl &= ~NFE_RX_START;
- }
- NFE_WRITE(sc, NFE_TX_CTL, txctl);
- NFE_WRITE(sc, NFE_RX_CTL, rxctl);
-
- NFE_UNLOCK(sc);
}
@@ -1714,6 +1726,10 @@ nfe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
}
#endif /* DEVICE_POLLING */
+ if ((mask & IFCAP_WOL_MAGIC) != 0 &&
+ (ifp->if_capabilities & IFCAP_WOL_MAGIC) != 0)
+ ifp->if_capenable ^= IFCAP_WOL_MAGIC;
+
if ((sc->nfe_flags & NFE_HW_CSUM) != 0 &&
(mask & IFCAP_HWCSUM) != 0) {
ifp->if_capenable ^= IFCAP_HWCSUM;
@@ -2746,7 +2762,8 @@ nfe_init_locked(void *xsc)
NFE_WRITE(sc, NFE_STATUS, sc->mii_phyaddr << 24 | NFE_STATUS_MAGIC);
NFE_WRITE(sc, NFE_SETUP_R4, NFE_R4_MAGIC);
- NFE_WRITE(sc, NFE_WOL_CTL, NFE_WOL_MAGIC);
+ /* Disable WOL. */
+ NFE_WRITE(sc, NFE_WOL_CTL, 0);
sc->rxtxctl &= ~NFE_RXTX_BIT2;
NFE_WRITE(sc, NFE_RXTX_CTL, sc->rxtxctl);
@@ -2917,18 +2934,8 @@ nfe_tick(void *xsc)
static int
nfe_shutdown(device_t dev)
{
- struct nfe_softc *sc;
- struct ifnet *ifp;
-
- sc = device_get_softc(dev);
- NFE_LOCK(sc);
- ifp = sc->nfe_ifp;
- nfe_stop(ifp);
- /* nfe_reset(sc); */
- NFE_UNLOCK(sc);
-
- return (0);
+ return (nfe_suspend(dev));
}
@@ -3212,3 +3219,115 @@ nfe_stats_update(struct nfe_softc *sc)
stats->rx_broadcast += NFE_READ(sc, NFE_TX_BROADCAST);
}
}
+
+
+static void
+nfe_set_linkspeed(struct nfe_softc *sc)
+{
+ struct mii_softc *miisc;
+ struct mii_data *mii;
+ int aneg, i, phyno;
+
+ NFE_LOCK_ASSERT(sc);
+
+ mii = device_get_softc(sc->nfe_miibus);
+ mii_pollstat(mii);
+ aneg = 0;
+ if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
+ (IFM_ACTIVE | IFM_AVALID)) {
+ switch IFM_SUBTYPE(mii->mii_media_active) {
+ case IFM_10_T:
+ case IFM_100_TX:
+ return;
+ case IFM_1000_T:
+ aneg++;
+ break;
+ default:
+ break;
+ }
+ }
+ phyno = 0;
+ if (mii->mii_instance) {
+ miisc = LIST_FIRST(&mii->mii_phys);
+ phyno = miisc->mii_phy;
+ LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
+ mii_phy_reset(miisc);
+ } else
+ return;
+ nfe_miibus_writereg(sc->nfe_dev, phyno, MII_100T2CR, 0);
+ nfe_miibus_writereg(sc->nfe_dev, phyno,
+ MII_ANAR, ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10 | ANAR_CSMA);
+ nfe_miibus_writereg(sc->nfe_dev, phyno,
+ MII_BMCR, BMCR_RESET | BMCR_AUTOEN | BMCR_STARTNEG);
+ DELAY(1000);
+ if (aneg != 0) {
+ /*
+ * Poll link state until nfe(4) get a 10/100Mbps link.
+ */
+ for (i = 0; i < MII_ANEGTICKS_GIGE; i++) {
+ mii_pollstat(mii);
+ if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID))
+ == (IFM_ACTIVE | IFM_AVALID)) {
+ switch (IFM_SUBTYPE(mii->mii_media_active)) {
+ case IFM_10_T:
+ case IFM_100_TX:
+ nfe_mac_config(sc, mii);
+ return;
+ default:
+ break;
+ }
+ }
+ NFE_UNLOCK(sc);
+ pause("nfelnk", hz);
+ NFE_LOCK(sc);
+ }
+ if (i == MII_ANEGTICKS_GIGE)
+ device_printf(sc->nfe_dev,
+ "establishing a link failed, WOL may not work!");
+ }
+ /*
+ * No link, force MAC to have 100Mbps, full-duplex link.
+ * This is the last resort and may/may not work.
+ */
+ mii->mii_media_status = IFM_AVALID | IFM_ACTIVE;
+ mii->mii_media_active = IFM_ETHER | IFM_100_TX | IFM_FDX;
+ nfe_mac_config(sc, mii);
+}
+
+
+static void
+nfe_set_wol(struct nfe_softc *sc)
+{
+ struct ifnet *ifp;
+ uint32_t wolctl;
+ int pmc;
+ uint16_t pmstat;
+
+ NFE_LOCK_ASSERT(sc);
+
+ if (pci_find_extcap(sc->nfe_dev, PCIY_PMG, &pmc) != 0)
+ return;
+ ifp = sc->nfe_ifp;
+ if ((ifp->if_capenable & IFCAP_WOL_MAGIC) != 0)
+ wolctl = NFE_WOL_MAGIC;
+ else
+ wolctl = 0;
+ NFE_WRITE(sc, NFE_WOL_CTL, wolctl);
+ if ((ifp->if_capenable & IFCAP_WOL_MAGIC) != 0) {
+ nfe_set_linkspeed(sc);
+ if ((sc->nfe_flags & NFE_PWR_MGMT) != 0)
+ NFE_WRITE(sc, NFE_PWR2_CTL,
+ NFE_READ(sc, NFE_PWR2_CTL) & ~NFE_PWR2_GATE_CLOCKS);
+ /* Enable RX. */
+ NFE_WRITE(sc, NFE_RX_RING_ADDR_HI, 0);
+ NFE_WRITE(sc, NFE_RX_RING_ADDR_LO, 0);
+ NFE_WRITE(sc, NFE_RX_CTL, NFE_READ(sc, NFE_RX_CTL) |
+ NFE_RX_START);
+ }
+ /* Request PME if WOL is requested. */
+ pmstat = pci_read_config(sc->nfe_dev, pmc + PCIR_POWER_STATUS, 2);
+ pmstat &= ~(PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE);
+ if ((ifp->if_capenable & IFCAP_WOL) != 0)
+ pmstat |= PCIM_PSTAT_PME | PCIM_PSTAT_PMEENABLE;
+ pci_write_config(sc->nfe_dev, pmc + PCIR_POWER_STATUS, pmstat, 2);
+}
diff --git a/sys/dev/nfe/if_nfereg.h b/sys/dev/nfe/if_nfereg.h
index d3671ab..59c88c7 100644
--- a/sys/dev/nfe/if_nfereg.h
+++ b/sys/dev/nfe/if_nfereg.h
@@ -190,6 +190,7 @@
#define NFE_PWR2_WAKEUP_MASK 0x0f11
#define NFE_PWR2_REVA3 (1 << 0)
+#define NFE_PWR2_GATE_CLOCKS 0x0f00
#define NFE_MEDIA_SET 0x10000
#define NFE_MEDIA_1000T 0x00032
diff --git a/sys/dev/nfe/if_nfevar.h b/sys/dev/nfe/if_nfevar.h
index 3686254..d2dbb1a 100644
--- a/sys/dev/nfe/if_nfevar.h
+++ b/sys/dev/nfe/if_nfevar.h
@@ -140,7 +140,6 @@ struct nfe_softc {
struct taskqueue *nfe_tq;
struct task nfe_int_task;
struct task nfe_tx_task;
- struct task nfe_link_task;
int nfe_link;
int nfe_suspended;
int nfe_framesize;
diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c
index d67b2e5..68d3149 100644
--- a/sys/dev/ofw/ofw_fdt.c
+++ b/sys/dev/ofw/ofw_fdt.c
@@ -221,7 +221,7 @@ ofw_fdt_instance_to_package(ofw_t ofw, ihandle_t instance)
*/
offset = fdt_node_offset_by_phandle(fdtp, instance);
if (offset < 0)
- return (0);
+ return (-1);
p = (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(phandle_t));
return (p);
@@ -236,7 +236,7 @@ ofw_fdt_getproplen(ofw_t ofw, phandle_t package, const char *propname)
offset = fdt_phandle_offset(package);
if (offset < 0)
- return (0);
+ return (-1);
if (strcmp(propname, "name") == 0) {
/* Emulate the 'name' property */
@@ -244,7 +244,7 @@ ofw_fdt_getproplen(ofw_t ofw, phandle_t package, const char *propname)
return (len + 1);
}
- len = 0;
+ len = -1;
prop = fdt_get_property(fdtp, offset, propname, &len);
return (len);
@@ -261,7 +261,7 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
offset = fdt_phandle_offset(package);
if (offset < 0)
- return (0);
+ return (-1);
if (strcmp(propname, "name") == 0) {
/* Emulate the 'name' property */
@@ -274,7 +274,7 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
prop = fdt_getprop(fdtp, offset, propname, &len);
if (prop == NULL)
- return (0);
+ return (-1);
if (len > buflen)
len = buflen;
@@ -314,7 +314,7 @@ fdt_nextprop(int offset, char *buf, size_t size)
depth = -1;
} while (depth >= 0);
- return (0);
+ return (-1);
}
/*
@@ -330,7 +330,7 @@ ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
offset = fdt_phandle_offset(package);
if (offset < 0)
- return (0);
+ return (-1);
if (previous == NULL)
/* Find the first prop in the node */
@@ -341,7 +341,7 @@ ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
*/
prop = fdt_get_property(fdtp, offset, previous, NULL);
if (prop == NULL)
- return (0);
+ return (-1);
offset = fdt_phandle_offset((phandle_t)prop);
rv = fdt_nextprop(offset, buf, size);
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c
index 8424fc2..a8cb8f7 100644
--- a/sys/dev/ofw/openfirm.c
+++ b/sys/dev/ofw/openfirm.c
@@ -76,7 +76,7 @@ MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties");
static ihandle_t stdout;
-static ofw_def_t *ofw_def_impl;
+static ofw_def_t *ofw_def_impl = NULL;
static ofw_t ofw_obj;
static struct ofw_kobj ofw_kernel_obj;
static struct kobj_ops ofw_kernel_kops;
@@ -118,6 +118,9 @@ OF_init(void *cookie)
phandle_t chosen;
int rv;
+ if (ofw_def_impl == NULL)
+ return (-1);
+
ofw_obj = &ofw_kernel_obj;
/*
* Take care of compiling the selected class, and
@@ -135,7 +138,6 @@ OF_init(void *cookie)
return (rv);
}
-#ifndef FDT
void
OF_printf(const char *fmt, ...)
{
@@ -157,9 +159,11 @@ int
OF_test(const char *name)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_TEST(ofw_obj, name));
}
-#endif
int
OF_interpret(const char *cmd, int nreturns, ...)
@@ -169,6 +173,9 @@ OF_interpret(const char *cmd, int nreturns, ...)
int i = 0;
int status;
+ if (ofw_def_impl == NULL)
+ return (-1);
+
status = OFW_INTERPRET(ofw_obj, cmd, nreturns, slots);
if (status == -1)
return (status);
@@ -190,6 +197,9 @@ phandle_t
OF_peer(phandle_t node)
{
+ if (ofw_def_impl == NULL)
+ return (0);
+
return (OFW_PEER(ofw_obj, node));
}
@@ -198,6 +208,9 @@ phandle_t
OF_child(phandle_t node)
{
+ if (ofw_def_impl == NULL)
+ return (0);
+
return (OFW_CHILD(ofw_obj, node));
}
@@ -206,6 +219,9 @@ phandle_t
OF_parent(phandle_t node)
{
+ if (ofw_def_impl == NULL)
+ return (0);
+
return (OFW_PARENT(ofw_obj, node));
}
@@ -214,6 +230,9 @@ phandle_t
OF_instance_to_package(ihandle_t instance)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_INSTANCE_TO_PACKAGE(ofw_obj, instance));
}
@@ -222,6 +241,9 @@ ssize_t
OF_getproplen(phandle_t package, const char *propname)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_GETPROPLEN(ofw_obj, package, propname));
}
@@ -230,6 +252,9 @@ ssize_t
OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_GETPROP(ofw_obj, package, propname, buf, buflen));
}
@@ -278,6 +303,9 @@ int
OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_NEXTPROP(ofw_obj, package, previous, buf, size));
}
@@ -286,6 +314,9 @@ int
OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_SETPROP(ofw_obj, package, propname, buf,len));
}
@@ -294,6 +325,9 @@ ssize_t
OF_canon(const char *device, char *buf, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_CANON(ofw_obj, device, buf, len));
}
@@ -302,6 +336,9 @@ phandle_t
OF_finddevice(const char *device)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_FINDDEVICE(ofw_obj, device));
}
@@ -310,6 +347,9 @@ ssize_t
OF_instance_to_path(ihandle_t instance, char *buf, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_INSTANCE_TO_PATH(ofw_obj, instance, buf, len));
}
@@ -318,10 +358,12 @@ ssize_t
OF_package_to_path(phandle_t package, char *buf, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len));
}
-#ifndef FDT
/* Call the method in the scope of a given instance. */
int
OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,
@@ -331,7 +373,7 @@ OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,
cell_t args_n_results[12];
int n, status;
- if (nargs > 6)
+ if (nargs > 6 || ofw_def_impl == NULL)
return (-1);
va_start(ap, nreturns);
for (n = 0; n < nargs; n++)
@@ -357,6 +399,9 @@ ihandle_t
OF_open(const char *device)
{
+ if (ofw_def_impl == NULL)
+ return (0);
+
return (OFW_OPEN(ofw_obj, device));
}
@@ -365,6 +410,9 @@ void
OF_close(ihandle_t instance)
{
+ if (ofw_def_impl == NULL)
+ return;
+
OFW_CLOSE(ofw_obj, instance);
}
@@ -373,6 +421,9 @@ ssize_t
OF_read(ihandle_t instance, void *addr, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_READ(ofw_obj, instance, addr, len));
}
@@ -381,6 +432,9 @@ ssize_t
OF_write(ihandle_t instance, const void *addr, size_t len)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_WRITE(ofw_obj, instance, addr, len));
}
@@ -389,6 +443,9 @@ int
OF_seek(ihandle_t instance, uint64_t pos)
{
+ if (ofw_def_impl == NULL)
+ return (-1);
+
return (OFW_SEEK(ofw_obj, instance, pos));
}
@@ -401,6 +458,9 @@ void *
OF_claim(void *virt, size_t size, u_int align)
{
+ if (ofw_def_impl == NULL)
+ return ((void *)-1);
+
return (OFW_CLAIM(ofw_obj, virt, size, align));
}
@@ -409,6 +469,9 @@ void
OF_release(void *virt, size_t size)
{
+ if (ofw_def_impl == NULL)
+ return;
+
OFW_RELEASE(ofw_obj, virt, size);
}
@@ -421,6 +484,9 @@ void
OF_enter()
{
+ if (ofw_def_impl == NULL)
+ return;
+
OFW_ENTER(ofw_obj);
}
@@ -429,10 +495,12 @@ void
OF_exit()
{
+ if (ofw_def_impl == NULL)
+ panic("OF_exit: Open Firmware not available");
+
/* Should not return */
OFW_EXIT(ofw_obj);
for (;;) /* just in case */
;
}
-#endif
diff --git a/sys/dev/pccard/pccardvar.h b/sys/dev/pccard/pccardvar.h
index 91f5362..1cfcd58 100644
--- a/sys/dev/pccard/pccardvar.h
+++ b/sys/dev/pccard/pccardvar.h
@@ -31,7 +31,7 @@
*/
/*
- * PCCARD_API_LEVEL. When set to 5, we provide a 5.x compatable API
+ * PCCARD_API_LEVEL. When set to 5, we provide a 5.x compatible API
* for driver writers that have to share their code between 5.x and 6.x.
* The 5.x compatibility interfaces will be unsupported in 7.0, at which
* point we'll only support 6 and newer, etc.
@@ -191,7 +191,7 @@ enum {
PCCARD_IVAR_PRODEXT,
PCCARD_IVAR_FUNCTION_NUMBER,
PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */
- PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */
+ PCCARD_IVAR_PRODUCT_STR,/* CIS string for "Product" */
PCCARD_IVAR_CIS3_STR,
PCCARD_IVAR_CIS4_STR,
PCCARD_IVAR_FUNCTION,
@@ -254,7 +254,7 @@ enum {
#endif
/*
- * Defines to decoe the get_funce_disk return value. See the PCMCIA standard
+ * Defines to decode the get_funce_disk return value. See the PCMCIA standard
* for all the details of what these bits mean.
*/
#define PFD_I_V_MASK 0x3
diff --git a/sys/dev/re/if_re.c b/sys/dev/re/if_re.c
index 95983af..35326cb 100644
--- a/sys/dev/re/if_re.c
+++ b/sys/dev/re/if_re.c
@@ -423,13 +423,12 @@ re_gmii_readreg(device_t dev, int phy, int reg)
}
CSR_WRITE_4(sc, RL_PHYAR, reg << 16);
- DELAY(1000);
for (i = 0; i < RL_PHY_TIMEOUT; i++) {
rval = CSR_READ_4(sc, RL_PHYAR);
if (rval & RL_PHYAR_BUSY)
break;
- DELAY(100);
+ DELAY(25);
}
if (i == RL_PHY_TIMEOUT) {
@@ -437,6 +436,11 @@ re_gmii_readreg(device_t dev, int phy, int reg)
return (0);
}
+ /*
+ * Controller requires a 20us delay to process next MDIO request.
+ */
+ DELAY(20);
+
return (rval & RL_PHYAR_PHYDATA);
}
@@ -451,13 +455,12 @@ re_gmii_writereg(device_t dev, int phy, int reg, int data)
CSR_WRITE_4(sc, RL_PHYAR, (reg << 16) |
(data & RL_PHYAR_PHYDATA) | RL_PHYAR_BUSY);
- DELAY(1000);
for (i = 0; i < RL_PHY_TIMEOUT; i++) {
rval = CSR_READ_4(sc, RL_PHYAR);
if (!(rval & RL_PHYAR_BUSY))
break;
- DELAY(100);
+ DELAY(25);
}
if (i == RL_PHY_TIMEOUT) {
@@ -465,6 +468,11 @@ re_gmii_writereg(device_t dev, int phy, int reg, int data)
return (0);
}
+ /*
+ * Controller requires a 20us delay to process next MDIO request.
+ */
+ DELAY(20);
+
return (0);
}
@@ -2707,6 +2715,24 @@ re_init_locked(struct rl_softc *sc)
*/
re_set_rxmode(sc);
+ /* Configure interrupt moderation. */
+ if (sc->rl_type == RL_8169) {
+ switch (sc->rl_hwrev) {
+ case RL_HWREV_8100E:
+ case RL_HWREV_8101E:
+ case RL_HWREV_8102E:
+ case RL_HWREV_8102EL:
+ case RL_HWREV_8102EL_SPIN1:
+ case RL_HWREV_8103E:
+ CSR_WRITE_2(sc, RL_INTRMOD, 0);
+ break;
+ default:
+ /* Magic from vendor. */
+ CSR_WRITE_2(sc, RL_INTRMOD, 0x5100);
+ break;
+ }
+ }
+
#ifdef DEVICE_POLLING
/*
* Disable interrupts if we are polling.
diff --git a/sys/dev/siis/siis.c b/sys/dev/siis/siis.c
index ba10c92..e75fd38 100644
--- a/sys/dev/siis/siis.c
+++ b/sys/dev/siis/siis.c
@@ -1208,6 +1208,17 @@ siis_end_transaction(struct siis_slot *slot, enum siis_err_type et)
res->sector_count_exp = ATA_INB(ch->r_mem, offs + 13);
} else
bzero(res, sizeof(*res));
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
+ ch->numrslots == 1) {
+ ccb->ataio.resid = ccb->ataio.dxfer_len -
+ ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
+ }
+ } else {
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN &&
+ ch->numrslots == 1) {
+ ccb->csio.resid = ccb->csio.dxfer_len -
+ ATA_INL(ch->r_mem, SIIS_P_LRAM_SLOT(slot->slot) + 4);
+ }
}
if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
bus_dmamap_sync(ch->dma.data_tag, slot->dma.data_map,
diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c
index 5a8c959..d9fae08 100644
--- a/sys/dev/sk/if_sk.c
+++ b/sys/dev/sk/if_sk.c
@@ -1319,8 +1319,10 @@ sk_attach(dev)
struct sk_softc *sc;
struct sk_if_softc *sc_if;
struct ifnet *ifp;
+ u_int32_t r;
int error, i, phy, port;
u_char eaddr[6];
+ u_char inv_mac[] = {0, 0, 0, 0, 0, 0};
if (dev == NULL)
return(EINVAL);
@@ -1400,6 +1402,23 @@ sk_attach(dev)
eaddr[i] =
sk_win_read_1(sc, SK_MAC0_0 + (port * 8) + i);
+ /* Verify whether the station address is invalid or not. */
+ if (bcmp(eaddr, inv_mac, sizeof(inv_mac)) == 0) {
+ device_printf(sc_if->sk_if_dev,
+ "Generating random ethernet address\n");
+ r = arc4random();
+ /*
+ * Set OUI to convenient locally assigned address. 'b'
+ * is 0x62, which has the locally assigned bit set, and
+ * the broadcast/multicast bit clear.
+ */
+ eaddr[0] = 'b';
+ eaddr[1] = 's';
+ eaddr[2] = 'd';
+ eaddr[3] = (r >> 16) & 0xff;
+ eaddr[4] = (r >> 8) & 0xff;
+ eaddr[5] = (r >> 0) & 0xff;
+ }
/*
* Set up RAM buffer addresses. The NIC will have a certain
* amount of SRAM on it, somewhere between 512K and 2MB. We
@@ -3337,6 +3356,7 @@ sk_init_yukon(sc_if)
u_int16_t reg;
struct sk_softc *sc;
struct ifnet *ifp;
+ u_int8_t *eaddr;
int i;
SK_IF_LOCK_ASSERT(sc_if);
@@ -3412,19 +3432,19 @@ sk_init_yukon(sc_if)
reg |= YU_SMR_MFL_JUMBO;
SK_YU_WRITE_2(sc_if, YUKON_SMR, reg);
- /* Setup Yukon's address */
- for (i = 0; i < 3; i++) {
- /* Write Source Address 1 (unicast filter) */
+ /* Setup Yukon's station address */
+ eaddr = IF_LLADDR(sc_if->sk_ifp);
+ for (i = 0; i < 3; i++)
+ SK_YU_WRITE_2(sc_if, SK_MAC0_0 + i * 4,
+ eaddr[i * 2] | eaddr[i * 2 + 1] << 8);
+ /* Set GMAC source address of flow control. */
+ for (i = 0; i < 3; i++)
SK_YU_WRITE_2(sc_if, YUKON_SAL1 + i * 4,
- IF_LLADDR(sc_if->sk_ifp)[i * 2] |
- IF_LLADDR(sc_if->sk_ifp)[i * 2 + 1] << 8);
- }
-
- for (i = 0; i < 3; i++) {
- reg = sk_win_read_2(sc_if->sk_softc,
- SK_MAC1_0 + i * 2 + sc_if->sk_port * 8);
- SK_YU_WRITE_2(sc_if, YUKON_SAL2 + i * 4, reg);
- }
+ eaddr[i * 2] | eaddr[i * 2 + 1] << 8);
+ /* Set GMAC virtual address. */
+ for (i = 0; i < 3; i++)
+ SK_YU_WRITE_2(sc_if, YUKON_SAL2 + i * 4,
+ eaddr[i * 2] | eaddr[i * 2 + 1] << 8);
/* Set Rx filter */
sk_rxfilter_yukon(sc_if);
diff --git a/sys/dev/sound/sbus/cs4231.c b/sys/dev/sound/sbus/cs4231.c
index c3981df..e643a4e 100644
--- a/sys/dev/sound/sbus/cs4231.c
+++ b/sys/dev/sound/sbus/cs4231.c
@@ -70,7 +70,7 @@ __FBSDID("$FreeBSD$");
* for playback/capture.
* Since I couldn't find any documentation for APCDMA programming
* information, I guessed the usage of APCDMA from that of OpenBSD's
- * driver. The EBDMA infomation of PCIO can be obtained from
+ * driver. The EBDMA information of PCIO can be obtained from
* http://solutions.sun.com/embedded/databook/web/microprocessors/pcio.html
* And CS4231A datasheet can also be obtained from
* ftp://ftp.alsa-project.org/pub/manuals/cirrus/4231a.pdf
@@ -1198,7 +1198,7 @@ cs4231_chan_fs(struct cs4231_softc *sc, int dir, u_int8_t fs)
/*
* capture channel
- * cs4231 doesn't allow seperate fs setup for playback/capture.
+ * cs4231 doesn't allow separate fs setup for playback/capture.
* I believe this will break full-duplex operation.
*/
if (dir == PCMDIR_REC) {
diff --git a/sys/dev/syscons/schistory.c b/sys/dev/syscons/schistory.c
index 860367b..c4c95cd 100644
--- a/sys/dev/syscons/schistory.c
+++ b/sys/dev/syscons/schistory.c
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
/*
* XXX Placeholder.
- * This calculations should be dynamically scaled by number of seperate sc
+ * This calculations should be dynamically scaled by number of separate sc
* devices. A base value of 'extra_history_size' should be defined for
* each syscons unit, and added and subtracted from the dynamic
* 'extra_history_size' as units are added and removed. This way, each time
@@ -86,7 +86,7 @@ int
sc_alloc_history_buffer(scr_stat *scp, int lines, int prev_ysize, int wait)
{
/*
- * syscons unconditionally allocates buffers upto
+ * syscons unconditionally allocates buffers up to
* SC_HISTORY_SIZE lines or scp->ysize lines, whichever
* is larger. A value greater than that is allowed,
* subject to extra_history_size.
@@ -116,7 +116,7 @@ sc_alloc_history_buffer(scr_stat *scp, int lines, int prev_ysize, int wait)
delta = cur_lines - min_lines;
}
- /* lines upto min_lines are always allowed. */
+ /* lines up to min_lines are always allowed. */
min_lines = imax(SC_HISTORY_SIZE, scp->ysize);
if (lines > min_lines) {
if (lines - min_lines > extra_history_size + delta) {
diff --git a/sys/dev/uart/uart_subr.c b/sys/dev/uart/uart_subr.c
index 2cab825..6b32c24 100644
--- a/sys/dev/uart/uart_subr.c
+++ b/sys/dev/uart/uart_subr.c
@@ -172,8 +172,8 @@ out:
/*
* Parse a device specification. The specification is a list of attributes
- * seperated by commas. Each attribute is a tag-value pair with the tag and
- * value seperated by a colon. Supported tags are:
+ * separated by commas. Each attribute is a tag-value pair with the tag and
+ * value separated by a colon. Supported tags are:
*
* br = Baudrate
* ch = Channel
diff --git a/sys/dev/usb/quirk/usb_quirk.c b/sys/dev/usb/quirk/usb_quirk.c
index c619a24..6691538 100644
--- a/sys/dev/usb/quirk/usb_quirk.c
+++ b/sys/dev/usb/quirk/usb_quirk.c
@@ -512,6 +512,16 @@ static const char *usb_quirk_str[USB_QUIRK_MAX] = {
[UQ_MSC_FORCE_PROTO_ATAPI] = "UQ_MSC_FORCE_PROTO_ATAPI",
[UQ_MSC_FORCE_PROTO_UFI] = "UQ_MSC_FORCE_PROTO_UFI",
[UQ_MSC_FORCE_PROTO_RBC] = "UQ_MSC_FORCE_PROTO_RBC",
+ [UQ_MSC_EJECT_HUAWEI] = "UQ_MSC_EJECT_HUAWEI",
+ [UQ_MSC_EJECT_SIERRA] = "UQ_MSC_EJECT_SIERRA",
+ [UQ_MSC_EJECT_SCSIEJECT] = "UQ_MSC_EJECT_SCSIEJECT",
+ [UQ_MSC_EJECT_REZERO] = "UQ_MSC_EJECT_REZERO",
+ [UQ_MSC_EJECT_ZTESTOR] = "UQ_MSC_EJECT_ZTESTOR",
+ [UQ_MSC_EJECT_CMOTECH] = "UQ_MSC_EJECT_CMOTECH",
+ [UQ_MSC_EJECT_WAIT] = "UQ_MSC_EJECT_WAIT",
+ [UQ_MSC_EJECT_SAEL_M460] = "UQ_MSC_EJECT_SAEL_M460",
+ [UQ_MSC_EJECT_HUAWEISCSI] = "UQ_MSC_EJECT_HUAWEISCSI",
+ [UQ_MSC_EJECT_TCT] = "UQ_MSC_EJECT_TCT",
};
/*------------------------------------------------------------------------*
diff --git a/sys/dev/usb/quirk/usb_quirk.h b/sys/dev/usb/quirk/usb_quirk.h
index d681402..522b15a 100644
--- a/sys/dev/usb/quirk/usb_quirk.h
+++ b/sys/dev/usb/quirk/usb_quirk.h
@@ -27,11 +27,14 @@
#ifndef _USB_QUIRK_H_
#define _USB_QUIRK_H_
-/* NOTE: UQ_NONE is not a valid quirk */
-enum { /* keep in sync with usb_quirk_str table */
- UQ_NONE,
+enum {
+ /*
+ * Keep in sync with theusb_quirk_str usb_quirk.c, and with the
+ * share/man/man4/usb_quirk.4
+ */
+ UQ_NONE, /* not a valid quirk */
- UQ_MATCH_VENDOR_ONLY,
+ UQ_MATCH_VENDOR_ONLY, /* match quirk on vendor only */
/* Various quirks */
@@ -59,31 +62,43 @@ enum { /* keep in sync with usb_quirk_str table */
UQ_CFG_INDEX_3, /* select configuration index 3 by default */
UQ_CFG_INDEX_4, /* select configuration index 4 by default */
UQ_CFG_INDEX_0, /* select configuration index 0 by default */
- UQ_ASSUME_CM_OVER_DATA, /* modem device breaks on cm over data */
+ UQ_ASSUME_CM_OVER_DATA, /* assume cm over data feature */
/* USB Mass Storage Quirks. See "storage/umass.c" for a detailed description. */
- UQ_MSC_NO_TEST_UNIT_READY,
- UQ_MSC_NO_RS_CLEAR_UA,
- UQ_MSC_NO_START_STOP,
- UQ_MSC_NO_GETMAXLUN,
- UQ_MSC_NO_INQUIRY,
- UQ_MSC_NO_INQUIRY_EVPD,
- UQ_MSC_NO_SYNC_CACHE,
- UQ_MSC_SHUTTLE_INIT,
- UQ_MSC_ALT_IFACE_1,
- UQ_MSC_FLOPPY_SPEED,
- UQ_MSC_IGNORE_RESIDUE,
- UQ_MSC_WRONG_CSWSIG,
- UQ_MSC_RBC_PAD_TO_12,
- UQ_MSC_READ_CAP_OFFBY1,
- UQ_MSC_FORCE_SHORT_INQ,
- UQ_MSC_FORCE_WIRE_BBB,
- UQ_MSC_FORCE_WIRE_CBI,
- UQ_MSC_FORCE_WIRE_CBI_I,
- UQ_MSC_FORCE_PROTO_SCSI,
- UQ_MSC_FORCE_PROTO_ATAPI,
- UQ_MSC_FORCE_PROTO_UFI,
- UQ_MSC_FORCE_PROTO_RBC,
+ UQ_MSC_NO_TEST_UNIT_READY, /* send start/stop instead of TUR */
+ UQ_MSC_NO_RS_CLEAR_UA, /* does not reset Unit Att. */
+ UQ_MSC_NO_START_STOP, /* does not support start/stop */
+ UQ_MSC_NO_GETMAXLUN, /* does not support get max LUN */
+ UQ_MSC_NO_INQUIRY, /* fake generic inq response */
+ UQ_MSC_NO_INQUIRY_EVPD, /* does not support inq EVPD */
+ UQ_MSC_NO_SYNC_CACHE, /* does not support sync cache */
+ UQ_MSC_SHUTTLE_INIT, /* requires Shuttle init sequence */
+ UQ_MSC_ALT_IFACE_1, /* switch to alternate interface 1 */
+ UQ_MSC_FLOPPY_SPEED, /* does floppy speeds (20kb/s) */
+ UQ_MSC_IGNORE_RESIDUE, /* gets residue wrong */
+ UQ_MSC_WRONG_CSWSIG, /* uses wrong CSW signature */
+ UQ_MSC_RBC_PAD_TO_12, /* pad RBC requests to 12 bytes */
+ UQ_MSC_READ_CAP_OFFBY1, /* reports sector count, not max sec. */
+ UQ_MSC_FORCE_SHORT_INQ, /* does not support full inq. */
+ UQ_MSC_FORCE_WIRE_BBB, /* force BBB wire protocol */
+ UQ_MSC_FORCE_WIRE_CBI, /* force CBI wire protocol */
+ UQ_MSC_FORCE_WIRE_CBI_I, /* force CBI with int. wire protocol */
+ UQ_MSC_FORCE_PROTO_SCSI, /* force SCSI command protocol */
+ UQ_MSC_FORCE_PROTO_ATAPI, /* force ATAPI command protocol */
+ UQ_MSC_FORCE_PROTO_UFI, /* force UFI command protocol */
+ UQ_MSC_FORCE_PROTO_RBC, /* force RBC command protocol */
+
+ /* Ejection of mass storage (driver disk) */
+ UQ_MSC_EJECT_HUAWEI, /* ejects after Huawei USB command */
+ UQ_MSC_EJECT_SIERRA, /* ejects after Sierra USB command */
+ UQ_MSC_EJECT_SCSIEJECT, /* ejects after SCSI eject command */
+ UQ_MSC_EJECT_REZERO, /* ejects after SCSI rezero command */
+ UQ_MSC_EJECT_ZTESTOR, /* ejects after ZTE SCSI command */
+ UQ_MSC_EJECT_CMOTECH, /* ejects after C-motech SCSI cmd */
+ UQ_MSC_EJECT_WAIT, /* wait for the device to eject */
+ UQ_MSC_EJECT_SAEL_M460, /* ejects after Sael USB commands */
+ UQ_MSC_EJECT_HUAWEISCSI, /* ejects after Huawei SCSI command */
+ UQ_MSC_EJECT_TCT, /* ejects after TCT SCSI command */
USB_QUIRK_MAX
};
diff --git a/sys/dev/usb/serial/u3g.c b/sys/dev/usb/serial/u3g.c
index 9376e9e..12bd3f4 100644
--- a/sys/dev/usb/serial/u3g.c
+++ b/sys/dev/usb/serial/u3g.c
@@ -62,6 +62,7 @@
#include <dev/usb/usb_msctest.h>
#include <dev/usb/serial/usb_serial.h>
+#include <dev/usb/quirk/usb_quirk.h>
#ifdef USB_DEBUG
static int u3g_debug = 0;
@@ -84,6 +85,7 @@ SYSCTL_INT(_hw_usb_u3g, OID_AUTO, debug, CTLFLAG_RW,
#define U3GSP_HSPA 6
#define U3GSP_MAX 7
+/* Eject methods; See also usb_quirks.h:UQ_MSC_EJECT_* */
#define U3GINIT_HUAWEI 1 /* Requires Huawei init command */
#define U3GINIT_SIERRA 2 /* Requires Sierra init command */
#define U3GINIT_SCSIEJECT 3 /* Requires SCSI eject command */
@@ -641,6 +643,7 @@ u3g_test_autoinst(void *arg, struct usb_device *udev,
struct usb_interface *iface;
struct usb_interface_descriptor *id;
int error;
+ unsigned long method;
if (uaa->dev_state != UAA_DEV_READY)
return;
@@ -651,16 +654,37 @@ u3g_test_autoinst(void *arg, struct usb_device *udev,
id = iface->idesc;
if (id == NULL || id->bInterfaceClass != UICLASS_MASS)
return;
- if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa))
+
+ if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEI))
+ method = U3GINIT_HUAWEI;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_SIERRA))
+ method = U3GINIT_SIERRA;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_SCSIEJECT))
+ method = U3GINIT_SCSIEJECT;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_REZERO))
+ method = U3GINIT_REZERO;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_ZTESTOR))
+ method = U3GINIT_ZTESTOR;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_CMOTECH))
+ method = U3GINIT_CMOTECH;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_WAIT))
+ method = U3GINIT_WAIT;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEISCSI))
+ method = U3GINIT_HUAWEISCSI;
+ else if (usb_test_quirk(uaa, UQ_MSC_EJECT_TCT))
+ method = U3GINIT_TCT;
+ else if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa) == 0)
+ method = USB_GET_DRIVER_INFO(uaa);
+ else
return; /* no device match */
if (bootverbose) {
- printf("Ejecting 0x%04x:0x%04x using method %ld\n",
- uaa->info.idVendor, uaa->info.idProduct,
- USB_GET_DRIVER_INFO(uaa));
+ printf("Ejecting %s %s using method %ld\n",
+ usb_get_manufacturer(udev),
+ usb_get_product(udev), method);
}
- switch (USB_GET_DRIVER_INFO(uaa)) {
+ switch (method) {
case U3GINIT_HUAWEI:
error = u3g_huawei_init(udev);
break;
@@ -752,8 +776,10 @@ u3g_attach(device_t dev)
DPRINTF("sc=%p\n", sc);
type = USB_GET_DRIVER_INFO(uaa);
- if (type == U3GINIT_SAEL_M460)
+ if (type == U3GINIT_SAEL_M460
+ || usb_test_quirk(uaa, UQ_MSC_EJECT_SAEL_M460)) {
u3g_sael_m460_init(uaa->device);
+ }
/* copy in USB config */
for (n = 0; n != U3G_N_TRANSFER; n++)
diff --git a/sys/dev/usb/serial/usb_serial.c b/sys/dev/usb/serial/usb_serial.c
index 9e9900a..4324a0c 100644
--- a/sys/dev/usb/serial/usb_serial.c
+++ b/sys/dev/usb/serial/usb_serial.c
@@ -200,9 +200,12 @@ ucom_unit_alloc(void)
mtx_lock(&ucom_bitmap_mtx);
- for (unit = 0; unit < UCOM_UNIT_MAX; unit++)
- if ((ucom_bitmap[unit / 8] & (1 << (unit % 8))) == 0)
+ for (unit = 0; unit < UCOM_UNIT_MAX; unit++) {
+ if ((ucom_bitmap[unit / 8] & (1 << (unit % 8))) == 0) {
+ ucom_bitmap[unit / 8] |= (1 << (unit % 8));
break;
+ }
+ }
mtx_unlock(&ucom_bitmap_mtx);
diff --git a/sys/dev/wb/if_wb.c b/sys/dev/wb/if_wb.c
index 1169cb7..33ad95a 100644
--- a/sys/dev/wb/if_wb.c
+++ b/sys/dev/wb/if_wb.c
@@ -857,7 +857,7 @@ wb_attach(dev)
*/
error = mii_attach(dev, &sc->wb_miibus, ifp, wb_ifmedia_upd,
wb_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
- if (error != 0) {
+ if (error != 0) {
device_printf(dev, "attaching PHYs failed\n");
goto fail;
}
diff --git a/sys/fs/nwfs/nwfs_vnops.c b/sys/fs/nwfs/nwfs_vnops.c
index e4f42b1..ddbdc16 100644
--- a/sys/fs/nwfs/nwfs_vnops.c
+++ b/sys/fs/nwfs/nwfs_vnops.c
@@ -39,8 +39,6 @@
#include <vm/vm.h>
#include <vm/vm_extern.h>
-#include <machine/mutex.h>
-
#include <netncp/ncp.h>
#include <netncp/ncp_conn.h>
#include <netncp/ncp_subr.h>
diff --git a/sys/geom/part/g_part.c b/sys/geom/part/g_part.c
index 155daae..b48ae11 100644
--- a/sys/geom/part/g_part.c
+++ b/sys/geom/part/g_part.c
@@ -296,6 +296,17 @@ g_part_new_provider(struct g_geom *gp, struct g_part_table *table,
g_error_provider(entry->gpe_pp, 0);
}
+static struct g_geom*
+g_part_find_geom(const char *name)
+{
+ struct g_geom *gp;
+ LIST_FOREACH(gp, &g_part_class.geom, geom) {
+ if (!strcmp(name, gp->name))
+ break;
+ }
+ return (gp);
+}
+
static int
g_part_parm_geom(struct gctl_req *req, const char *name, struct g_geom **v)
{
@@ -307,10 +318,7 @@ g_part_parm_geom(struct gctl_req *req, const char *name, struct g_geom **v)
return (ENOATTR);
if (strncmp(gname, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
gname += sizeof(_PATH_DEV) - 1;
- LIST_FOREACH(gp, &g_part_class.geom, geom) {
- if (!strcmp(gname, gp->name))
- break;
- }
+ gp = g_part_find_geom(gname);
if (gp == NULL) {
gctl_error(req, "%d %s '%s'", EINVAL, name, gname);
return (EINVAL);
@@ -748,8 +756,8 @@ g_part_ctl_create(struct gctl_req *req, struct g_part_parms *gpp)
g_topology_assert();
/* Check that there isn't already a g_part geom on the provider. */
- error = g_part_parm_geom(req, "provider", &gp);
- if (!error) {
+ gp = g_part_find_geom(pp->name);
+ if (gp != NULL) {
null = gp->softc;
if (null->gpt_scheme != &g_part_null_scheme) {
gctl_error(req, "%d geom '%s'", EEXIST, pp->name);
diff --git a/sys/i386/acpica/OsdEnvironment.c b/sys/i386/acpica/OsdEnvironment.c
deleted file mode 100644
index ec5e19c..0000000
--- a/sys/i386/acpica/OsdEnvironment.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * Copyright (c) 2000,2001 Michael Smith
- * Copyright (c) 2000 BSDi
- * 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.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * 6.1 : Environmental support
- */
-#include <sys/types.h>
-#include <sys/bus.h>
-#include <sys/linker_set.h>
-#include <sys/sysctl.h>
-
-#include <contrib/dev/acpica/include/acpi.h>
-#include <contrib/dev/acpica/include/actables.h>
-
-static u_long i386_acpi_root;
-
-SYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &i386_acpi_root, 0,
- "The physical address of the RSDP");
-
-ACPI_STATUS
-AcpiOsInitialize(void)
-{
- return(0);
-}
-
-ACPI_STATUS
-AcpiOsTerminate(void)
-{
- return(0);
-}
-
-ACPI_PHYSICAL_ADDRESS
-AcpiOsGetRootPointer(void)
-{
- u_long ptr;
-
- if (i386_acpi_root == 0 &&
- (resource_long_value("acpi", 0, "rsdp", (long *)&ptr) == 0 ||
- AcpiFindRootPointer((ACPI_SIZE *)&ptr) == AE_OK) &&
- ptr != 0)
- i386_acpi_root = ptr;
-
- return (i386_acpi_root);
-}
diff --git a/sys/i386/acpica/acpi_machdep.c b/sys/i386/acpica/acpi_machdep.c
index 7ea57d9..0f5d5b8 100644
--- a/sys/i386/acpica/acpi_machdep.c
+++ b/sys/i386/acpica/acpi_machdep.c
@@ -29,15 +29,10 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/bus.h>
-#include <sys/condvar.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/module.h>
-#include <sys/poll.h>
#include <sys/sysctl.h>
-#include <sys/uio.h>
+
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -46,469 +41,30 @@ __FBSDID("$FreeBSD$");
#include <contrib/dev/acpica/include/actables.h>
#include <dev/acpica/acpivar.h>
-#include <dev/acpica/acpiio.h>
#include <machine/nexusvar.h>
-/*
- * APM driver emulation
- */
-
-#include <machine/apm_bios.h>
-#include <machine/pc/bios.h>
-
-#include <i386/bios/apm.h>
-
SYSCTL_DECL(_debug_acpi);
uint32_t acpi_resume_beep;
TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep);
SYSCTL_UINT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep,
0, "Beep the PC speaker when resuming");
+
uint32_t acpi_reset_video;
TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video);
static int intr_model = ACPI_INTR_PIC;
-static int apm_active;
-static struct clonedevs *apm_clones;
-
-MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation");
-
-static d_open_t apmopen;
-static d_close_t apmclose;
-static d_write_t apmwrite;
-static d_ioctl_t apmioctl;
-static d_poll_t apmpoll;
-static d_kqfilter_t apmkqfilter;
-static void apmreadfiltdetach(struct knote *kn);
-static int apmreadfilt(struct knote *kn, long hint);
-static struct filterops apm_readfiltops = {
- .f_isfd = 1,
- .f_detach = apmreadfiltdetach,
- .f_event = apmreadfilt,
-};
-
-static struct cdevsw apm_cdevsw = {
- .d_version = D_VERSION,
- .d_flags = D_TRACKCLOSE | D_NEEDMINOR,
- .d_open = apmopen,
- .d_close = apmclose,
- .d_write = apmwrite,
- .d_ioctl = apmioctl,
- .d_poll = apmpoll,
- .d_name = "apm",
- .d_kqfilter = apmkqfilter
-};
-
-static int
-acpi_capm_convert_battstate(struct acpi_battinfo *battp)
-{
- int state;
-
- state = APM_UNKNOWN;
-
- if (battp->state & ACPI_BATT_STAT_DISCHARG) {
- if (battp->cap >= 50)
- state = 0; /* high */
- else
- state = 1; /* low */
- }
- if (battp->state & ACPI_BATT_STAT_CRITICAL)
- state = 2; /* critical */
- if (battp->state & ACPI_BATT_STAT_CHARGING)
- state = 3; /* charging */
-
- /* If still unknown, determine it based on the battery capacity. */
- if (state == APM_UNKNOWN) {
- if (battp->cap >= 50)
- state = 0; /* high */
- else
- state = 1; /* low */
- }
-
- return (state);
-}
-
-static int
-acpi_capm_convert_battflags(struct acpi_battinfo *battp)
-{
- int flags;
-
- flags = 0;
-
- if (battp->cap >= 50)
- flags |= APM_BATT_HIGH;
- else {
- if (battp->state & ACPI_BATT_STAT_CRITICAL)
- flags |= APM_BATT_CRITICAL;
- else
- flags |= APM_BATT_LOW;
- }
- if (battp->state & ACPI_BATT_STAT_CHARGING)
- flags |= APM_BATT_CHARGING;
- if (battp->state == ACPI_BATT_STAT_NOT_PRESENT)
- flags = APM_BATT_NOT_PRESENT;
-
- return (flags);
-}
-
-static int
-acpi_capm_get_info(apm_info_t aip)
-{
- int acline;
- struct acpi_battinfo batt;
-
- aip->ai_infoversion = 1;
- aip->ai_major = 1;
- aip->ai_minor = 2;
- aip->ai_status = apm_active;
- aip->ai_capabilities= 0xff00; /* unknown */
-
- if (acpi_acad_get_acline(&acline))
- aip->ai_acline = APM_UNKNOWN; /* unknown */
- else
- aip->ai_acline = acline; /* on/off */
-
- if (acpi_battery_get_battinfo(NULL, &batt) != 0) {
- aip->ai_batt_stat = APM_UNKNOWN;
- aip->ai_batt_life = APM_UNKNOWN;
- aip->ai_batt_time = -1; /* unknown */
- aip->ai_batteries = ~0U; /* unknown */
- } else {
- aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
- aip->ai_batt_life = batt.cap;
- aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
- aip->ai_batteries = acpi_battery_get_units();
- }
-
- return (0);
-}
-
-static int
-acpi_capm_get_pwstatus(apm_pwstatus_t app)
-{
- device_t dev;
- int acline, unit, error;
- struct acpi_battinfo batt;
-
- if (app->ap_device != PMDV_ALLDEV &&
- (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
- return (1);
-
- if (app->ap_device == PMDV_ALLDEV)
- error = acpi_battery_get_battinfo(NULL, &batt);
- else {
- unit = app->ap_device - PMDV_BATT0;
- dev = devclass_get_device(devclass_find("battery"), unit);
- if (dev != NULL)
- error = acpi_battery_get_battinfo(dev, &batt);
- else
- error = ENXIO;
- }
- if (error)
- return (1);
-
- app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
- app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
- app->ap_batt_life = batt.cap;
- app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
-
- if (acpi_acad_get_acline(&acline))
- app->ap_acline = APM_UNKNOWN;
- else
- app->ap_acline = acline; /* on/off */
-
- return (0);
-}
-
-/* Create single-use devices for /dev/apm and /dev/apmctl. */
-static void
-apm_clone(void *arg, struct ucred *cred, char *name, int namelen,
- struct cdev **dev)
-{
- int ctl_dev, unit;
-
- if (*dev != NULL)
- return;
- if (strcmp(name, "apmctl") == 0)
- ctl_dev = TRUE;
- else if (strcmp(name, "apm") == 0)
- ctl_dev = FALSE;
- else
- return;
-
- /* Always create a new device and unit number. */
- unit = -1;
- if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) {
- if (ctl_dev) {
- *dev = make_dev(&apm_cdevsw, unit,
- UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit);
- } else {
- *dev = make_dev(&apm_cdevsw, unit,
- UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit);
- }
- if (*dev != NULL) {
- dev_ref(*dev);
- (*dev)->si_flags |= SI_CHEAPCLONE;
- }
- }
-}
-
-/* Create a struct for tracking per-device suspend notification. */
-static struct apm_clone_data *
-apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc)
-{
- struct apm_clone_data *clone;
-
- clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK);
- clone->cdev = dev;
- clone->acpi_sc = acpi_sc;
- clone->notify_status = APM_EV_NONE;
- bzero(&clone->sel_read, sizeof(clone->sel_read));
- knlist_init_mtx(&clone->sel_read.si_note, &acpi_mutex);
-
- /*
- * The acpi device is always managed by devd(8) and is considered
- * writable (i.e., ack is required to allow suspend to proceed.)
- */
- if (strcmp("acpi", devtoname(dev)) == 0)
- clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE;
- else
- clone->flags = ACPI_EVF_NONE;
-
- ACPI_LOCK(acpi);
- STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries);
- ACPI_UNLOCK(acpi);
- return (clone);
-}
-
-static int
-apmopen(struct cdev *dev, int flag, int fmt, struct thread *td)
-{
- struct acpi_softc *acpi_sc;
- struct apm_clone_data *clone;
-
- acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
- clone = apm_create_clone(dev, acpi_sc);
- dev->si_drv1 = clone;
-
- /* If the device is opened for write, record that. */
- if ((flag & FWRITE) != 0)
- clone->flags |= ACPI_EVF_WRITE;
-
- return (0);
-}
-
-static int
-apmclose(struct cdev *dev, int flag, int fmt, struct thread *td)
-{
- struct apm_clone_data *clone;
- struct acpi_softc *acpi_sc;
-
- clone = dev->si_drv1;
- acpi_sc = clone->acpi_sc;
-
- /* We are about to lose a reference so check if suspend should occur */
- if (acpi_sc->acpi_next_sstate != 0 &&
- clone->notify_status != APM_EV_ACKED)
- acpi_AckSleepState(clone, 0);
-
- /* Remove this clone's data from the list and free it. */
- ACPI_LOCK(acpi);
- STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries);
- knlist_destroy(&clone->sel_read.si_note);
- ACPI_UNLOCK(acpi);
- free(clone, M_APMDEV);
- destroy_dev_sched(dev);
- return (0);
-}
-
-static int
-apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
-{
- int error;
- struct apm_clone_data *clone;
- struct acpi_softc *acpi_sc;
- struct apm_info info;
- struct apm_event_info *ev_info;
- apm_info_old_t aiop;
-
- error = 0;
- clone = dev->si_drv1;
- acpi_sc = clone->acpi_sc;
-
- switch (cmd) {
- case APMIO_SUSPEND:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- if (acpi_sc->acpi_next_sstate == 0) {
- if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) {
- error = acpi_ReqSleepState(acpi_sc,
- acpi_sc->acpi_suspend_sx);
- } else {
- printf(
- "power off via apm suspend not supported\n");
- error = ENXIO;
- }
- } else
- error = acpi_AckSleepState(clone, 0);
- break;
- case APMIO_STANDBY:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- if (acpi_sc->acpi_next_sstate == 0) {
- if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) {
- error = acpi_ReqSleepState(acpi_sc,
- acpi_sc->acpi_standby_sx);
- } else {
- printf(
- "power off via apm standby not supported\n");
- error = ENXIO;
- }
- } else
- error = acpi_AckSleepState(clone, 0);
- break;
- case APMIO_NEXTEVENT:
- printf("apm nextevent start\n");
- ACPI_LOCK(acpi);
- if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status ==
- APM_EV_NONE) {
- ev_info = (struct apm_event_info *)addr;
- if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3)
- ev_info->type = PMEV_STANDBYREQ;
- else
- ev_info->type = PMEV_SUSPENDREQ;
- ev_info->index = 0;
- clone->notify_status = APM_EV_NOTIFIED;
- printf("apm event returning %d\n", ev_info->type);
- } else
- error = EAGAIN;
- ACPI_UNLOCK(acpi);
- break;
- case APMIO_GETINFO_OLD:
- if (acpi_capm_get_info(&info))
- error = ENXIO;
- aiop = (apm_info_old_t)addr;
- aiop->ai_major = info.ai_major;
- aiop->ai_minor = info.ai_minor;
- aiop->ai_acline = info.ai_acline;
- aiop->ai_batt_stat = info.ai_batt_stat;
- aiop->ai_batt_life = info.ai_batt_life;
- aiop->ai_status = info.ai_status;
- break;
- case APMIO_GETINFO:
- if (acpi_capm_get_info((apm_info_t)addr))
- error = ENXIO;
- break;
- case APMIO_GETPWSTATUS:
- if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
- error = ENXIO;
- break;
- case APMIO_ENABLE:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- apm_active = 1;
- break;
- case APMIO_DISABLE:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- apm_active = 0;
- break;
- case APMIO_HALTCPU:
- break;
- case APMIO_NOTHALTCPU:
- break;
- case APMIO_DISPLAY:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- break;
- case APMIO_BIOS:
- if ((flag & FWRITE) == 0)
- return (EPERM);
- bzero(addr, sizeof(struct apm_bios_arg));
- break;
- default:
- error = EINVAL;
- break;
- }
-
- return (error);
-}
-
-static int
-apmwrite(struct cdev *dev, struct uio *uio, int ioflag)
-{
- return (uio->uio_resid);
-}
-
-static int
-apmpoll(struct cdev *dev, int events, struct thread *td)
-{
- struct apm_clone_data *clone;
- int revents;
-
- revents = 0;
- ACPI_LOCK(acpi);
- clone = dev->si_drv1;
- if (clone->acpi_sc->acpi_next_sstate)
- revents |= events & (POLLIN | POLLRDNORM);
- else
- selrecord(td, &clone->sel_read);
- ACPI_UNLOCK(acpi);
- return (revents);
-}
-
-static int
-apmkqfilter(struct cdev *dev, struct knote *kn)
-{
- struct apm_clone_data *clone;
-
- ACPI_LOCK(acpi);
- clone = dev->si_drv1;
- kn->kn_hook = clone;
- kn->kn_fop = &apm_readfiltops;
- knlist_add(&clone->sel_read.si_note, kn, 0);
- ACPI_UNLOCK(acpi);
- return (0);
-}
-
-static void
-apmreadfiltdetach(struct knote *kn)
-{
- struct apm_clone_data *clone;
-
- ACPI_LOCK(acpi);
- clone = kn->kn_hook;
- knlist_remove(&clone->sel_read.si_note, kn, 0);
- ACPI_UNLOCK(acpi);
-}
-
-static int
-apmreadfilt(struct knote *kn, long hint)
-{
- struct apm_clone_data *clone;
- int sleeping;
-
- ACPI_LOCK(acpi);
- clone = kn->kn_hook;
- sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0;
- ACPI_UNLOCK(acpi);
- return (sleeping);
-}
int
acpi_machdep_init(device_t dev)
{
- struct acpi_softc *acpi_sc;
+ struct acpi_softc *sc;
- acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
+ sc = device_get_softc(dev);
- /* Create a clone for /dev/acpi also. */
- STAILQ_INIT(&acpi_sc->apm_cdevs);
- acpi_sc->acpi_clone = apm_create_clone(acpi_sc->acpi_dev_t, acpi_sc);
- clone_setup(&apm_clones);
- EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000);
- acpi_install_wakeup_handler(acpi_sc);
+ acpi_apm_init(sc);
+ acpi_install_wakeup_handler(sc);
if (intr_model == ACPI_INTR_PIC)
BUS_CONFIG_INTR(dev, AcpiGbl_FADT.SciInterrupt,
@@ -516,8 +72,8 @@ acpi_machdep_init(device_t dev)
else
acpi_SetIntrModel(intr_model);
- SYSCTL_ADD_UINT(&acpi_sc->acpi_sysctl_ctx,
- SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
+ SYSCTL_ADD_UINT(&sc->acpi_sysctl_ctx,
+ SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO,
"reset_video", CTLFLAG_RW, &acpi_reset_video, 0,
"Call the VESA reset BIOS vector on the resume path");
@@ -556,6 +112,7 @@ acpi_machdep_quirks(int *quirks)
void
acpi_cpu_c1()
{
+
__asm __volatile("sti; hlt");
}
diff --git a/sys/i386/bios/apm.c b/sys/i386/bios/apm.c
index e015cd0..f33bafd 100644
--- a/sys/i386/bios/apm.c
+++ b/sys/i386/bios/apm.c
@@ -1389,6 +1389,23 @@ apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td
return (EPERM);
/* XXX compatibility with the old interface */
args = (struct apm_bios_arg *)addr;
+#ifdef PC98
+ if (((args->eax >> 8) & 0xff) == 0x53) {
+ sc->bios.r.eax = args->eax & ~0xffff;
+ sc->bios.r.eax |= APM_BIOS << 8;
+ switch (args->eax & 0xff) {
+ case 0x0a:
+ sc->bios.r.eax |= APM_GETPWSTATUS;
+ break;
+ case 0x0e:
+ sc->bios.r.eax |= APM_DRVVERSION;
+ break;
+ default:
+ sc->bios.r.eax |= args->eax & 0xff;
+ break;
+ }
+ } else
+#endif
sc->bios.r.eax = args->eax;
sc->bios.r.ebx = args->ebx;
sc->bios.r.ecx = args->ecx;
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 0fbd519..f89de32 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -40,7 +40,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include "opt_apic.h"
#include "opt_atalk.h"
#include "opt_compat.h"
#include "opt_cpu.h"
@@ -3614,102 +3613,6 @@ user_dbreg_trap(void)
return 0;
}
-#ifndef DEV_APIC
-#include <machine/apicvar.h>
-
-/*
- * Provide stub functions so that the MADT APIC enumerator in the acpi
- * kernel module will link against a kernel without 'device apic'.
- *
- * XXX - This is a gross hack.
- */
-void
-apic_register_enumerator(struct apic_enumerator *enumerator)
-{
-}
-
-void *
-ioapic_create(vm_paddr_t addr, int32_t apic_id, int intbase)
-{
- return (NULL);
-}
-
-int
-ioapic_disable_pin(void *cookie, u_int pin)
-{
- return (ENXIO);
-}
-
-int
-ioapic_get_vector(void *cookie, u_int pin)
-{
- return (-1);
-}
-
-void
-ioapic_register(void *cookie)
-{
-}
-
-int
-ioapic_remap_vector(void *cookie, u_int pin, int vector)
-{
- return (ENXIO);
-}
-
-int
-ioapic_set_extint(void *cookie, u_int pin)
-{
- return (ENXIO);
-}
-
-int
-ioapic_set_nmi(void *cookie, u_int pin)
-{
- return (ENXIO);
-}
-
-int
-ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol)
-{
- return (ENXIO);
-}
-
-int
-ioapic_set_triggermode(void *cookie, u_int pin, enum intr_trigger trigger)
-{
- return (ENXIO);
-}
-
-void
-lapic_create(u_int apic_id, int boot_cpu)
-{
-}
-
-void
-lapic_init(vm_paddr_t addr)
-{
-}
-
-int
-lapic_set_lvt_mode(u_int apic_id, u_int lvt, u_int32_t mode)
-{
- return (ENXIO);
-}
-
-int
-lapic_set_lvt_polarity(u_int apic_id, u_int lvt, enum intr_polarity pol)
-{
- return (ENXIO);
-}
-
-int
-lapic_set_lvt_triggermode(u_int apic_id, u_int lvt, enum intr_trigger trigger)
-{
- return (ENXIO);
-}
-#endif
-
#ifdef KDB
/*
diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c
index c4d2672..871ccb4 100644
--- a/sys/i386/i386/mp_machdep.c
+++ b/sys/i386/i386/mp_machdep.c
@@ -465,8 +465,10 @@ cpu_add(u_int apic_id, char boot_cpu)
boot_cpu_id = apic_id;
cpu_info[apic_id].cpu_bsp = 1;
}
- if (mp_ncpus < MAXCPU)
+ if (mp_ncpus < MAXCPU) {
mp_ncpus++;
+ mp_maxid = mp_ncpus - 1;
+ }
if (bootverbose)
printf("SMP: Added CPU %d (%s)\n", apic_id, boot_cpu ? "BSP" :
"AP");
@@ -476,7 +478,19 @@ void
cpu_mp_setmaxid(void)
{
- mp_maxid = MAXCPU - 1;
+ /*
+ * mp_maxid should be already set by calls to cpu_add().
+ * Just sanity check its value here.
+ */
+ if (mp_ncpus == 0)
+ KASSERT(mp_maxid == 0,
+ ("%s: mp_ncpus is zero, but mp_maxid is not", __func__));
+ else if (mp_ncpus == 1)
+ mp_maxid = 0;
+ else
+ KASSERT(mp_maxid >= mp_ncpus - 1,
+ ("%s: counters out of sync: max %d, count %d", __func__,
+ mp_maxid, mp_ncpus));
}
int
@@ -504,6 +518,7 @@ cpu_mp_probe(void)
* One CPU was found, so this must be a UP system with
* an I/O APIC.
*/
+ mp_maxid = 0;
return (0);
}
diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c
index 80444e6..65a529e 100644
--- a/sys/i386/i386/pmap.c
+++ b/sys/i386/i386/pmap.c
@@ -1678,11 +1678,19 @@ pmap_unuse_pt(pmap_t pmap, vm_offset_t va, vm_page_t *free)
return (pmap_unwire_pte_hold(pmap, mpte, free));
}
+/*
+ * Initialize the pmap for the swapper process.
+ */
void
pmap_pinit0(pmap_t pmap)
{
PMAP_LOCK_INIT(pmap);
+ /*
+ * Since the page table directory is shared with the kernel pmap,
+ * which is already included in the list "allpmaps", this pmap does
+ * not need to be inserted into that list.
+ */
pmap->pm_pdir = (pd_entry_t *)(KERNBASE + (vm_offset_t)IdlePTD);
#ifdef PAE
pmap->pm_pdpt = (pdpt_entry_t *)(KERNBASE + (vm_offset_t)IdlePDPT);
@@ -1692,9 +1700,6 @@ pmap_pinit0(pmap_t pmap)
PCPU_SET(curpmap, pmap);
TAILQ_INIT(&pmap->pm_pvchunk);
bzero(&pmap->pm_stats, sizeof pmap->pm_stats);
- mtx_lock_spin(&allpmaps_lock);
- LIST_INSERT_HEAD(&allpmaps, pmap, pm_list);
- mtx_unlock_spin(&allpmaps_lock);
}
/*
@@ -1759,9 +1764,9 @@ pmap_pinit(pmap_t pmap)
mtx_lock_spin(&allpmaps_lock);
LIST_INSERT_HEAD(&allpmaps, pmap, pm_list);
- mtx_unlock_spin(&allpmaps_lock);
- /* Wire in kernel global address entries. */
+ /* Copy the kernel page table directory entries. */
bcopy(PTD + KPTDI, pmap->pm_pdir + KPTDI, nkpt * sizeof(pd_entry_t));
+ mtx_unlock_spin(&allpmaps_lock);
/* install self-referential address mapping entry(s) */
for (i = 0; i < NPGPTD; i++) {
diff --git a/sys/i386/include/apm_bios.h b/sys/i386/include/apm_bios.h
index 424852d..9cc0eee 100644
--- a/sys/i386/include/apm_bios.h
+++ b/sys/i386/include/apm_bios.h
@@ -1,264 +1,6 @@
/*-
- * APM (Advanced Power Management) BIOS Device Driver
- *
- * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
- *
- * This software may be used, modified, copied, and distributed, in
- * both source and binary form provided that the above copyright and
- * these terms are retained. Under no circumstances is the author
- * responsible for the proper functioning of this software, nor does
- * the author assume any responsibility for damages incurred with its
- * use.
- *
- * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
- *
- * $FreeBSD$
+ * This file is in the public domain.
*/
+/* $FreeBSD$ */
-#ifndef _MACHINE_APM_BIOS_H_
-#define _MACHINE_APM_BIOS_H_
-
-#ifndef _KERNEL
-#include <sys/types.h>
-#endif
-#include <sys/ioccom.h>
-
-/* BIOS id */
-#define APM_BIOS 0x53
-#define APM_INT 0x15
-
-/* APM flags */
-#define APM_16BIT_SUPPORT 0x01
-#define APM_32BIT_SUPPORT 0x02
-#define APM_CPUIDLE_SLOW 0x04
-#define APM_DISABLED 0x08
-#define APM_DISENGAGED 0x10
-
-/* APM initializer physical address */
-#define APM_OURADDR 0x00080000
-
-/* APM functions */
-#define APM_INSTCHECK 0x00
-#define APM_REALCONNECT 0x01
-#define APM_PROT16CONNECT 0x02
-#define APM_PROT32CONNECT 0x03
-#define APM_DISCONNECT 0x04
-#define APM_CPUIDLE 0x05
-#define APM_CPUBUSY 0x06
-#define APM_SETPWSTATE 0x07
-#define APM_ENABLEDISABLEPM 0x08
-#define APM_RESTOREDEFAULT 0x09
-#define APM_GETPWSTATUS 0x0a
-#define APM_GETPMEVENT 0x0b
-#define APM_GETPWSTATE 0x0c
-#define APM_ENABLEDISABLEDPM 0x0d
-#define APM_DRVVERSION 0x0e
-#define APM_ENGAGEDISENGAGEPM 0x0f
-#define APM_GETCAPABILITIES 0x10
-#define APM_RESUMETIMER 0x11
-#define APM_RESUMEONRING 0x12
-#define APM_TIMERREQUESTS 0x13
-#define APM_OEMFUNC 0x80
-
-/* error code */
-#define APME_OK 0x00
-#define APME_PMDISABLED 0x01
-#define APME_REALESTABLISHED 0x02
-#define APME_NOTCONNECTED 0x03
-#define APME_PROT16ESTABLISHED 0x05
-#define APME_PROT16NOTSUPPORTED 0x06
-#define APME_PROT32ESTABLISHED 0x07
-#define APME_PROT32NOTDUPPORTED 0x08
-#define APME_UNKNOWNDEVICEID 0x09
-#define APME_OUTOFRANGE 0x0a
-#define APME_NOTENGAGED 0x0b
-#define APME_CANTENTERSTATE 0x60
-#define APME_NOPMEVENT 0x80
-#define APME_NOAPMPRESENT 0x86
-
-
-/* device code */
-#define PMDV_APMBIOS 0x0000
-#define PMDV_ALLDEV 0x0001
-#define PMDV_DISP0 0x0100
-#define PMDV_DISP1 0x0101
-#define PMDV_DISPALL 0x01ff
-#define PMDV_2NDSTORAGE0 0x0200
-#define PMDV_2NDSTORAGE1 0x0201
-#define PMDV_2NDSTORAGE2 0x0202
-#define PMDV_2NDSTORAGE3 0x0203
-#define PMDV_PARALLEL0 0x0300
-#define PMDV_PARALLEL1 0x0301
-#define PMDV_SERIAL0 0x0400
-#define PMDV_SERIAL1 0x0401
-#define PMDV_SERIAL2 0x0402
-#define PMDV_SERIAL3 0x0403
-#define PMDV_SERIAL4 0x0404
-#define PMDV_SERIAL5 0x0405
-#define PMDV_SERIAL6 0x0406
-#define PMDV_SERIAL7 0x0407
-#define PMDV_NET0 0x0500
-#define PMDV_NET1 0x0501
-#define PMDV_NET2 0x0502
-#define PMDV_NET3 0x0503
-#define PMDV_PCMCIA0 0x0600
-#define PMDV_PCMCIA1 0x0601
-#define PMDV_PCMCIA2 0x0602
-#define PMDV_PCMCIA3 0x0603
-/* 0x0700 - 0x7fff Reserved */
-#define PMDV_BATT_BASE 0x8000
-#define PMDV_BATT0 0x8001
-#define PMDV_BATT1 0x8002
-#define PMDV_BATT_ALL 0x80ff
-/* 0x8100 - 0xdfff Reserved */
-/* 0xe000 - 0xefff OEM-defined power device IDs */
-/* 0xf000 - 0xffff Reserved */
-
-/* Power state */
-#define PMST_APMENABLED 0x0000
-#define PMST_STANDBY 0x0001
-#define PMST_SUSPEND 0x0002
-#define PMST_OFF 0x0003
-#define PMST_LASTREQNOTIFY 0x0004
-#define PMST_LASTREQREJECT 0x0005
-/* 0x0006 - 0x001f Reserved system states */
-/* 0x0020 - 0x003f OEM-defined system states */
-/* 0x0040 - 0x007f OEM-defined device states */
-/* 0x0080 - 0xffff Reserved device states */
-
-#if !defined(ASSEMBLER) && !defined(INITIALIZER)
-
-/* C definitions */
-struct apmhook {
- struct apmhook *ah_next;
- int (*ah_fun)(void *ah_arg);
- void *ah_arg;
- const char *ah_name;
- int ah_order;
-};
-#define APM_HOOK_NONE (-1)
-#define APM_HOOK_SUSPEND 0
-#define APM_HOOK_RESUME 1
-#define NAPM_HOOK 2
-
-#ifdef _KERNEL
-
-void apm_suspend(int state);
-struct apmhook *apm_hook_establish (int apmh, struct apmhook *);
-void apm_hook_disestablish (int apmh, struct apmhook *);
-void apm_cpu_idle(void);
-void apm_cpu_busy(void);
-
-#endif
-
-#endif /* !ASSEMBLER && !INITIALIZER */
-
-#define APM_MIN_ORDER 0x00
-#define APM_MID_ORDER 0x80
-#define APM_MAX_ORDER 0xff
-
-/* power management event code */
-#define PMEV_NOEVENT 0x0000
-#define PMEV_STANDBYREQ 0x0001
-#define PMEV_SUSPENDREQ 0x0002
-#define PMEV_NORMRESUME 0x0003
-#define PMEV_CRITRESUME 0x0004
-#define PMEV_BATTERYLOW 0x0005
-#define PMEV_POWERSTATECHANGE 0x0006
-#define PMEV_UPDATETIME 0x0007
-#define PMEV_CRITSUSPEND 0x0008
-#define PMEV_USERSTANDBYREQ 0x0009
-#define PMEV_USERSUSPENDREQ 0x000a
-#define PMEV_STANDBYRESUME 0x000b
-#define PMEV_CAPABILITIESCHANGE 0x000c
-/* 0x000d - 0x00ff Reserved system events */
-/* 0x0100 - 0x01ff Reserved device events */
-/* 0x0200 - 0x02ff OEM-defined APM events */
-/* 0x0300 - 0xffff Reserved */
-#define PMEV_DEFAULT 0xffffffff /* used for customization */
-
-#if !defined(ASSEMBLER) && !defined(INITIALIZER)
-
-/*
- * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This
- * is for backward compatibility with old executables.
- */
-typedef struct apm_info_old {
- u_int ai_major; /* APM major version */
- u_int ai_minor; /* APM minor version */
- u_int ai_acline; /* AC line status */
- u_int ai_batt_stat; /* Battery status */
- u_int ai_batt_life; /* Remaining battery life */
- u_int ai_status; /* Status of APM support (enabled/disabled) */
-} *apm_info_old_t;
-
-/*
- * Structure returned by the APMIO_GETINFO ioctl.
- *
- * In the comments below, the parenthesized numbers indicate the minimum
- * value of ai_infoversion for which each field is valid.
- */
-typedef struct apm_info {
- u_int ai_infoversion; /* Indicates which fields are valid */
- u_int ai_major; /* APM major version (0) */
- u_int ai_minor; /* APM minor version (0) */
- u_int ai_acline; /* AC line status (0) */
- u_int ai_batt_stat; /* Battery status (0) */
- u_int ai_batt_life; /* Remaining battery life in percent (0) */
- int ai_batt_time; /* Remaining battery time in seconds (0) */
- u_int ai_status; /* True if enabled (0) */
- u_int ai_batteries; /* Number of batteries (1) */
- u_int ai_capabilities;/* APM Capabilities (1) */
- u_int ai_spare[6]; /* For future expansion */
-} *apm_info_t;
-
-/* Battery flag */
-#define APM_BATT_HIGH 0x01
-#define APM_BATT_LOW 0x02
-#define APM_BATT_CRITICAL 0x04
-#define APM_BATT_CHARGING 0x08
-#define APM_BATT_NOT_PRESENT 0x10
-#define APM_BATT_NO_SYSTEM 0x80
-
-typedef struct apm_pwstatus {
- u_int ap_device; /* Device code of battery */
- u_int ap_acline; /* AC line status (0) */
- u_int ap_batt_stat; /* Battery status (0) */
- u_int ap_batt_flag; /* Battery flag (0) */
- u_int ap_batt_life; /* Remaining battery life in percent (0) */
- int ap_batt_time; /* Remaining battery time in seconds (0) */
-} *apm_pwstatus_t;
-
-struct apm_bios_arg {
- uint32_t eax;
- uint32_t ebx;
- uint32_t ecx;
- uint32_t edx;
- uint32_t esi;
- uint32_t edi;
-};
-
-struct apm_event_info {
- u_int type;
- u_int index;
- u_int spare[8];
-};
-
-#define APMIO_SUSPEND _IO('P', 1)
-#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old)
-#define APMIO_ENABLE _IO('P', 5)
-#define APMIO_DISABLE _IO('P', 6)
-#define APMIO_HALTCPU _IO('P', 7)
-#define APMIO_NOTHALTCPU _IO('P', 8)
-#define APMIO_DISPLAY _IOW('P', 9, int)
-#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg)
-#define APMIO_GETINFO _IOR('P', 11, struct apm_info)
-#define APMIO_STANDBY _IO('P', 12)
-#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus)
-/* for /dev/apmctl */
-#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info)
-#define APMIO_REJECTLASTREQ _IO('P', 101)
-
-#endif /* !ASSEMBLER && !INITIALIZER */
-
-#endif /* !_MACHINE_APM_BIOS_H_ */
+#include <x86/apm_bios.h>
diff --git a/sys/i386/include/mptable.h b/sys/i386/include/mptable.h
deleted file mode 100644
index 451d9ce..0000000
--- a/sys/i386/include/mptable.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*-
- * Copyright (c) 1996, by Steve Passe
- * 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. The name of the developer 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$
- */
-
-#ifndef __MACHINE_MPTABLE_H__
-#define __MACHINE_MPTABLE_H__
-
-enum busTypes {
- NOBUS = 0,
- EISA = 3,
- ISA = 6,
- MCA = 9,
- PCI = 13,
- MAX_BUSTYPE = 18,
- UNKNOWN_BUSTYPE = 0xff
-};
-
-/* MP Floating Pointer Structure */
-typedef struct MPFPS {
- char signature[4];
- u_int32_t pap;
- u_char length;
- u_char spec_rev;
- u_char checksum;
- u_char config_type;
- u_char mpfb2;
- u_char mpfb3;
- u_char mpfb4;
- u_char mpfb5;
-} *mpfps_t;
-
-#define MPFB2_IMCR_PRESENT 0x80
-#define MPFB2_MUL_CLK_SRCS 0x40
-
-/* MP Configuration Table Header */
-typedef struct MPCTH {
- char signature[4];
- u_short base_table_length;
- u_char spec_rev;
- u_char checksum;
- u_char oem_id[8];
- u_char product_id[12];
- u_int32_t oem_table_pointer;
- u_short oem_table_size;
- u_short entry_count;
- u_int32_t apic_address;
- u_short extended_table_length;
- u_char extended_table_checksum;
- u_char reserved;
-} *mpcth_t;
-
-#define MPCT_ENTRY_PROCESSOR 0
-#define MPCT_ENTRY_BUS 1
-#define MPCT_ENTRY_IOAPIC 2
-#define MPCT_ENTRY_INT 3
-#define MPCT_ENTRY_LOCAL_INT 4
-
-typedef struct PROCENTRY {
- u_char type;
- u_char apic_id;
- u_char apic_version;
- u_char cpu_flags;
- u_long cpu_signature;
- u_long feature_flags;
- u_long reserved1;
- u_long reserved2;
-} *proc_entry_ptr;
-
-#define PROCENTRY_FLAG_EN 0x01
-#define PROCENTRY_FLAG_BP 0x02
-
-typedef struct BUSENTRY {
- u_char type;
- u_char bus_id;
- char bus_type[6];
-} *bus_entry_ptr;
-
-typedef struct IOAPICENTRY {
- u_char type;
- u_char apic_id;
- u_char apic_version;
- u_char apic_flags;
- u_int32_t apic_address;
-} *io_apic_entry_ptr;
-
-#define IOAPICENTRY_FLAG_EN 0x01
-
-typedef struct INTENTRY {
- u_char type;
- u_char int_type;
- u_short int_flags;
- u_char src_bus_id;
- u_char src_bus_irq;
- u_char dst_apic_id;
- u_char dst_apic_int;
-} *int_entry_ptr;
-
-#define INTENTRY_TYPE_INT 0
-#define INTENTRY_TYPE_NMI 1
-#define INTENTRY_TYPE_SMI 2
-#define INTENTRY_TYPE_EXTINT 3
-
-#define INTENTRY_FLAGS_POLARITY 0x3
-#define INTENTRY_FLAGS_POLARITY_CONFORM 0x0
-#define INTENTRY_FLAGS_POLARITY_ACTIVEHI 0x1
-#define INTENTRY_FLAGS_POLARITY_ACTIVELO 0x3
-#define INTENTRY_FLAGS_TRIGGER 0xc
-#define INTENTRY_FLAGS_TRIGGER_CONFORM 0x0
-#define INTENTRY_FLAGS_TRIGGER_EDGE 0x4
-#define INTENTRY_FLAGS_TRIGGER_LEVEL 0xc
-
-/* descriptions of MP basetable entries */
-typedef struct BASETABLE_ENTRY {
- u_char type;
- u_char length;
- char name[16];
-} basetable_entry;
-
-#ifdef _KERNEL
-int mptable_pci_probe_table(int bus);
-int mptable_pci_route_interrupt(device_t pcib, device_t dev, int pin);
-#endif
-#endif /* !__MACHINE_MPTABLE_H__ */
diff --git a/sys/i386/include/mutex.h b/sys/i386/include/mutex.h
deleted file mode 100644
index 651e226..0000000
--- a/sys/i386/include/mutex.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright (c) 1997 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.
- * 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. Berkeley Software Design Inc's name may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * 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.
- *
- * from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#ifdef LOCORE
-
-/*
- * Simple assembly macros to get and release mutexes.
- *
- * Note: All of these macros accept a "flags" argument and are analoguous
- * to the mtx_lock_flags and mtx_unlock_flags general macros. If one
- * desires to not pass a flag, the value 0 may be passed as second
- * argument.
- *
- * XXX: We only have MTX_LOCK_SPIN and MTX_UNLOCK_SPIN for now, since that's
- * all we use right now. We should add MTX_LOCK and MTX_UNLOCK (for sleep
- * locks) in the near future, however.
- */
-#define MTX_LOCK_SPIN(lck, flags) \
- pushl $0 ; \
- pushl $0 ; \
- pushl $flags ; \
- pushl $lck ; \
- call _mtx_lock_spin_flags ; \
- addl $0x10, %esp ; \
-
-#define MTX_UNLOCK_SPIN(lck) \
- pushl $0 ; \
- pushl $0 ; \
- pushl $0 ; \
- pushl $lck ; \
- call _mtx_unlock_spin_flags ; \
- addl $0x10, %esp ; \
-
-#endif /* LOCORE */
-#endif /* __MACHINE_MUTEX_H */
diff --git a/sys/i386/xen/mptable.c b/sys/i386/xen/mptable.c
index fe01cd5..22019ea 100644
--- a/sys/i386/xen/mptable.c
+++ b/sys/i386/xen/mptable.c
@@ -38,11 +38,11 @@ __FBSDID("$FreeBSD$");
#include <vm/pmap.h>
#include <x86/apicreg.h>
+#include <x86/mptable.h>
#include <machine/frame.h>
#include <machine/intr_machdep.h>
#include <machine/apicvar.h>
#include <machine/md_var.h>
-#include <machine/mptable.h>
#include <machine/specialreg.h>
#include <xen/hypervisor.h>
@@ -109,7 +109,7 @@ mptable_register(void *dummy __unused)
apic_register_enumerator(&mptable_enumerator);
}
-SYSINIT(mptable_register, SI_SUB_CPU - 1, SI_ORDER_FIRST, mptable_register,
+SYSINIT(mptable_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, mptable_register,
NULL);
diff --git a/sys/ia64/acpica/OsdEnvironment.c b/sys/ia64/acpica/OsdEnvironment.c
index 209e343..654ffad 100644
--- a/sys/ia64/acpica/OsdEnvironment.c
+++ b/sys/ia64/acpica/OsdEnvironment.c
@@ -35,8 +35,6 @@ __FBSDID("$FreeBSD$");
#include <contrib/dev/acpica/include/acpi.h>
-static struct uuid acpi_root_uuid = EFI_TABLE_ACPI20;
-
static u_long acpi_root_phys;
SYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &acpi_root_phys, 0,
@@ -46,27 +44,35 @@ ACPI_STATUS
AcpiOsInitialize(void)
{
- return(AE_OK);
+ return (AE_OK);
}
ACPI_STATUS
AcpiOsTerminate(void)
{
- return(AE_OK);
+ return (AE_OK);
+}
+
+static u_long
+acpi_get_root_from_efi(void)
+{
+ static struct uuid acpi_root_uuid = EFI_TABLE_ACPI20;
+ void *acpi_root;
+
+ acpi_root = efi_get_table(&acpi_root_uuid);
+ if (acpi_root != NULL)
+ return (IA64_RR_MASK((uintptr_t)acpi_root));
+
+ return (0);
}
ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer(void)
{
- void *acpi_root;
- if (acpi_root_phys == 0) {
- acpi_root = efi_get_table(&acpi_root_uuid);
- if (acpi_root == NULL)
- return (0);
- acpi_root_phys = IA64_RR_MASK((u_long)acpi_root);
- }
+ if (acpi_root_phys == 0)
+ acpi_root_phys = acpi_get_root_from_efi();
return (acpi_root_phys);
}
diff --git a/sys/ia64/ia64/db_machdep.c b/sys/ia64/ia64/db_machdep.c
index 75f698c..22bf336 100644
--- a/sys/ia64/ia64/db_machdep.c
+++ b/sys/ia64/ia64/db_machdep.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <machine/frame.h>
#include <machine/kdb.h>
#include <machine/md_var.h>
-#include <machine/mutex.h>
#include <machine/pcb.h>
#include <machine/setjmp.h>
#include <machine/unwind.h>
diff --git a/sys/ia64/ia64/genassym.c b/sys/ia64/ia64/genassym.c
index d81054b..66a6cd4 100644
--- a/sys/ia64/ia64/genassym.c
+++ b/sys/ia64/ia64/genassym.c
@@ -49,7 +49,6 @@
#include <sys/resourcevar.h>
#include <sys/ucontext.h>
#include <machine/frame.h>
-#include <machine/mutex.h>
#include <machine/elf.h>
#include <machine/pal.h>
#include <machine/pcb.h>
diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index 119c36f..b5b409a 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -88,7 +88,6 @@ __FBSDID("$FreeBSD$");
#include <machine/intr.h>
#include <machine/mca.h>
#include <machine/md_var.h>
-#include <machine/mutex.h>
#include <machine/pal.h>
#include <machine/pcb.h>
#include <machine/reg.h>
diff --git a/sys/ia64/include/mutex.h b/sys/ia64/include/mutex.h
deleted file mode 100644
index 96d8f3d..0000000
--- a/sys/ia64/include/mutex.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1997 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.
- * 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. Berkeley Software Design Inc's name may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * 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.
- *
- * from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#ifdef LOCORE
-
-/*
- * Simple assembly macros to get and release non-recursive spin locks
- */
-#define MTX_ENTER(lck, rPSR, rOLD, rNEW, rLCK) \
- mov rPSR=psr ; \
- mov rNEW=pcpup ; \
- addl rLCK=@ltoff(lck),gp ;; \
- ld8 rLCK=[rLCK] ;; \
- add rLCK=MTX_LOCK,rLCK ;; \
- rsm psr.i ; \
- mov ar.ccv=MTX_UNOWNED ; \
- add rNEW=PC_CURTHREAD,rNEW ;; \
- ld8 rNEW=[rNEW] ;; \
-1: cmpxchg8.acq rOLD=[rLCK],rNEW,ar.ccv ;; \
- cmp.eq p1,p0=MTX_UNOWNED,rOLD ;; \
-(p1) br.cond.spnt.few 1b ;; \
- addl rLCK=@ltoff(lck),gp ;; \
- ld8 rLCK=[rLCK] ;; \
- add rLCK=MTX_SAVEINTR,rLCK ;; \
- st4 [rLCK]=rPSR
-
-#define MTX_EXIT(lck, rTMP, rLCK) \
- mov rTMP=MTX_UNOWNED ; \
- addl rLCK=@ltoff(lck),gp;; \
- ld8 rLCK=[rLCK];; \
- add rLCK=MTX_LOCK,rLCK;; \
- st8.rel [rLCK]=rTMP,MTX_SAVEINTR-MTX_LOCK ;; \
- ld4 rTMP=[rLCK] ;; \
- mov psr.l=rTMP ;; \
- srlz.d
-
-#endif /* !LOCORE */
-
-#endif /* __MACHINE_MUTEX_H */
diff --git a/sys/kern/kern_clocksource.c b/sys/kern/kern_clocksource.c
index e654659..ded6d64 100644
--- a/sys/kern/kern_clocksource.c
+++ b/sys/kern/kern_clocksource.c
@@ -208,12 +208,13 @@ handleevents(struct bintime *now, int fake)
bintime_add(&state->nexthard, &hardperiod);
runs++;
}
- if (runs) {
+ if (runs && fake < 2) {
hardclock_anycpu(runs, usermode);
done = 1;
}
while (bintime_cmp(now, &state->nextstat, >=)) {
- statclock(usermode);
+ if (fake < 2)
+ statclock(usermode);
bintime_add(&state->nextstat, &statperiod);
done = 1;
}
@@ -227,6 +228,10 @@ handleevents(struct bintime *now, int fake)
} else
state->nextprof = state->nextstat;
getnextcpuevent(&t, 0);
+ if (fake == 2) {
+ state->nextevent = t;
+ return (done);
+ }
ET_HW_LOCK(state);
if (!busy) {
state->idle = 0;
@@ -383,6 +388,11 @@ loadtimer(struct bintime *now, int start)
uint64_t tmp;
int eq;
+ if (timer->et_flags & ET_FLAGS_PERCPU) {
+ state = DPCPU_PTR(timerstate);
+ next = &state->nexttick;
+ } else
+ next = &nexttick;
if (periodic) {
if (start) {
/*
@@ -391,20 +401,18 @@ loadtimer(struct bintime *now, int start)
*/
tmp = ((uint64_t)now->sec << 36) + (now->frac >> 28);
tmp = (tmp % (timerperiod.frac >> 28)) << 28;
- tmp = timerperiod.frac - tmp;
- new = timerperiod;
- bintime_addx(&new, tmp);
+ new.sec = 0;
+ new.frac = timerperiod.frac - tmp;
+ if (new.frac < tmp) /* Left less then passed. */
+ bintime_add(&new, &timerperiod);
CTR5(KTR_SPARE2, "load p at %d: now %d.%08x first in %d.%08x",
curcpu, now->sec, (unsigned int)(now->frac >> 32),
new.sec, (unsigned int)(new.frac >> 32));
+ *next = new;
+ bintime_add(next, now);
et_start(timer, &new, &timerperiod);
}
} else {
- if (timer->et_flags & ET_FLAGS_PERCPU) {
- state = DPCPU_PTR(timerstate);
- next = &state->nexttick;
- } else
- next = &nexttick;
getnextevent(&new);
eq = bintime_cmp(&new, next, ==);
CTR5(KTR_SPARE2, "load at %d: next %d.%08x%08x eq %d",
@@ -669,13 +677,19 @@ cpu_initclocks_ap(void)
struct bintime now;
struct pcpu_state *state;
- if (timer->et_flags & ET_FLAGS_PERCPU) {
- state = DPCPU_PTR(timerstate);
- binuptime(&now);
- ET_HW_LOCK(state);
+ state = DPCPU_PTR(timerstate);
+ binuptime(&now);
+ ET_HW_LOCK(state);
+ if ((timer->et_flags & ET_FLAGS_PERCPU) == 0 && periodic) {
+ state->now = nexttick;
+ bintime_sub(&state->now, &timerperiod);
+ } else
+ state->now = now;
+ hardclock_sync(curcpu);
+ handleevents(&state->now, 2);
+ if (timer->et_flags & ET_FLAGS_PERCPU)
loadtimer(&now, 1);
- ET_HW_UNLOCK(state);
- }
+ ET_HW_UNLOCK(state);
}
/*
diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c
index 509ce775f..897a4c0 100644
--- a/sys/kern/kern_conf.c
+++ b/sys/kern/kern_conf.c
@@ -752,7 +752,7 @@ make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit,
return (res);
}
dev = newdev(devsw, unit, dev_new);
- if ((dev->si_flags & SI_NAMED) == 0)
+ if ((dev->si_flags & SI_NAMED) == 0) {
res = prep_devname(dev, fmt, ap);
if (res != 0) {
if ((flags & MAKEDEV_CHECKNAME) == 0) {
@@ -766,6 +766,7 @@ make_dev_credv(int flags, struct cdev **dres, struct cdevsw *devsw, int unit,
devfs_free(dev);
}
return (res);
+ }
}
if (flags & MAKEDEV_REF)
dev_refl(dev);
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index c0bef50..041b480 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -200,7 +200,7 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE,
file, line, NULL);
- _get_sleep_lock(m, curthread, opts, file, line);
+ __mtx_lock(m, curthread, opts, file, line);
LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file,
line);
WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line);
@@ -224,7 +224,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
if (m->mtx_recurse == 0)
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_UNLOCK_RELEASE, m);
- _rel_sleep_lock(m, curthread, opts, file, line);
+ __mtx_unlock(m, curthread, opts, file, line);
}
void
@@ -243,7 +243,7 @@ _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line)
m->lock_object.lo_name, file, line));
WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE,
file, line, NULL);
- _get_spin_lock(m, curthread, opts, file, line);
+ __mtx_lock_spin(m, curthread, opts, file, line);
LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file,
line);
WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line);
@@ -264,7 +264,7 @@ _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
line);
mtx_assert(m, MA_OWNED);
- _rel_spin_lock(m);
+ __mtx_unlock_spin(m);
}
/*
@@ -293,7 +293,7 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
rval = 1;
} else
- rval = _obtain_lock(m, (uintptr_t)curthread);
+ rval = _mtx_obtain_lock(m, (uintptr_t)curthread);
LOCK_LOG_TRY("LOCK", &m->lock_object, opts, rval, file, line);
if (rval) {
@@ -355,7 +355,7 @@ _mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file,
"_mtx_lock_sleep: %s contested (lock=%p) at %s:%d",
m->lock_object.lo_name, (void *)m->mtx_lock, file, line);
- while (!_obtain_lock(m, tid)) {
+ while (!_mtx_obtain_lock(m, tid)) {
#ifdef KDTRACE_HOOKS
spin_cnt++;
#endif
@@ -511,7 +511,7 @@ _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file,
CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime);
- while (!_obtain_lock(m, tid)) {
+ while (!_mtx_obtain_lock(m, tid)) {
/* Give interrupts a chance while we spin. */
spinlock_exit();
@@ -569,7 +569,7 @@ retry:
m->lock_object.lo_name, file, line));
WITNESS_CHECKORDER(&m->lock_object,
opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL);
- while (!_obtain_lock(m, tid)) {
+ while (!_mtx_obtain_lock(m, tid)) {
#ifdef KDTRACE_HOOKS
spin_cnt++;
#endif
@@ -597,7 +597,7 @@ retry:
}
if (m == td->td_lock)
break;
- _rel_spin_lock(m); /* does spinlock_exit() */
+ __mtx_unlock_spin(m); /* does spinlock_exit() */
#ifdef KDTRACE_HOOKS
spin_cnt++;
#endif
@@ -673,7 +673,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m);
MPASS(ts != NULL);
turnstile_broadcast(ts, TS_EXCLUSIVE_QUEUE);
- _release_lock_quick(m);
+ _mtx_release_lock_quick(m);
/*
* This turnstile is now no longer associated with the mutex. We can
@@ -685,7 +685,7 @@ _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line)
/*
* All the unlocking of MTX_SPIN locks is done inline.
- * See the _rel_spin_lock() macro for the details.
+ * See the __mtx_unlock_spin() macro for the details.
*/
/*
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 286ba2e..ad4e8d9 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -778,18 +778,16 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
rufetch(p, &kp->ki_rusage);
kp->ki_runtime = cputick2usec(p->p_rux.rux_runtime);
PROC_SUNLOCK(p);
- if ((p->p_flag & P_INMEM) && p->p_stats != NULL) {
- kp->ki_start = p->p_stats->p_start;
- timevaladd(&kp->ki_start, &boottime);
- PROC_SLOCK(p);
- calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
- PROC_SUNLOCK(p);
- calccru(p, &kp->ki_childutime, &kp->ki_childstime);
-
- /* Some callers want child-times in a single value */
- kp->ki_childtime = kp->ki_childstime;
- timevaladd(&kp->ki_childtime, &kp->ki_childutime);
- }
+ kp->ki_start = p->p_stats->p_start;
+ timevaladd(&kp->ki_start, &boottime);
+ PROC_SLOCK(p);
+ calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
+ PROC_SUNLOCK(p);
+ calccru(p, &kp->ki_childutime, &kp->ki_childstime);
+
+ /* Some callers want child-times in a single value */
+ kp->ki_childtime = kp->ki_childstime;
+ timevaladd(&kp->ki_childtime, &kp->ki_childutime);
tp = NULL;
if (p->p_pgrp) {
kp->ki_pgid = p->p_pgrp->pg_id;
diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c
index eaaefde..1e0bac1 100644
--- a/sys/kern/link_elf.c
+++ b/sys/kern/link_elf.c
@@ -74,52 +74,52 @@ __FBSDID("$FreeBSD$");
#define MAXSEGS 4
typedef struct elf_file {
- struct linker_file lf; /* Common fields */
- int preloaded; /* Was file pre-loaded */
- caddr_t address; /* Relocation address */
+ struct linker_file lf; /* Common fields */
+ int preloaded; /* Was file pre-loaded */
+ caddr_t address; /* Relocation address */
#ifdef SPARSE_MAPPING
- vm_object_t object; /* VM object to hold file pages */
+ vm_object_t object; /* VM object to hold file pages */
#endif
- Elf_Dyn* dynamic; /* Symbol table etc. */
- Elf_Hashelt nbuckets; /* DT_HASH info */
- Elf_Hashelt nchains;
- const Elf_Hashelt* buckets;
- const Elf_Hashelt* chains;
- caddr_t hash;
- caddr_t strtab; /* DT_STRTAB */
- int strsz; /* DT_STRSZ */
- const Elf_Sym* symtab; /* DT_SYMTAB */
- Elf_Addr* got; /* DT_PLTGOT */
- const Elf_Rel* pltrel; /* DT_JMPREL */
- int pltrelsize; /* DT_PLTRELSZ */
- const Elf_Rela* pltrela; /* DT_JMPREL */
- int pltrelasize; /* DT_PLTRELSZ */
- const Elf_Rel* rel; /* DT_REL */
- int relsize; /* DT_RELSZ */
- const Elf_Rela* rela; /* DT_RELA */
- int relasize; /* DT_RELASZ */
- caddr_t modptr;
- const Elf_Sym* ddbsymtab; /* The symbol table we are using */
- long ddbsymcnt; /* Number of symbols */
- caddr_t ddbstrtab; /* String table */
- long ddbstrcnt; /* number of bytes in string table */
- caddr_t symbase; /* malloc'ed symbold base */
- caddr_t strbase; /* malloc'ed string base */
- caddr_t ctftab; /* CTF table */
- long ctfcnt; /* number of bytes in CTF table */
- caddr_t ctfoff; /* CTF offset table */
- caddr_t typoff; /* Type offset table */
- long typlen; /* Number of type entries. */
- Elf_Addr pcpu_start; /* Pre-relocation pcpu set start. */
- Elf_Addr pcpu_stop; /* Pre-relocation pcpu set stop. */
- Elf_Addr pcpu_base; /* Relocated pcpu set address. */
+ Elf_Dyn *dynamic; /* Symbol table etc. */
+ Elf_Hashelt nbuckets; /* DT_HASH info */
+ Elf_Hashelt nchains;
+ const Elf_Hashelt *buckets;
+ const Elf_Hashelt *chains;
+ caddr_t hash;
+ caddr_t strtab; /* DT_STRTAB */
+ int strsz; /* DT_STRSZ */
+ const Elf_Sym *symtab; /* DT_SYMTAB */
+ Elf_Addr *got; /* DT_PLTGOT */
+ const Elf_Rel *pltrel; /* DT_JMPREL */
+ int pltrelsize; /* DT_PLTRELSZ */
+ const Elf_Rela *pltrela; /* DT_JMPREL */
+ int pltrelasize; /* DT_PLTRELSZ */
+ const Elf_Rel *rel; /* DT_REL */
+ int relsize; /* DT_RELSZ */
+ const Elf_Rela *rela; /* DT_RELA */
+ int relasize; /* DT_RELASZ */
+ caddr_t modptr;
+ const Elf_Sym *ddbsymtab; /* The symbol table we are using */
+ long ddbsymcnt; /* Number of symbols */
+ caddr_t ddbstrtab; /* String table */
+ long ddbstrcnt; /* number of bytes in string table */
+ caddr_t symbase; /* malloc'ed symbold base */
+ caddr_t strbase; /* malloc'ed string base */
+ caddr_t ctftab; /* CTF table */
+ long ctfcnt; /* number of bytes in CTF table */
+ caddr_t ctfoff; /* CTF offset table */
+ caddr_t typoff; /* Type offset table */
+ long typlen; /* Number of type entries. */
+ Elf_Addr pcpu_start; /* Pre-relocation pcpu set start. */
+ Elf_Addr pcpu_stop; /* Pre-relocation pcpu set stop. */
+ Elf_Addr pcpu_base; /* Relocated pcpu set address. */
#ifdef VIMAGE
- Elf_Addr vnet_start; /* Pre-relocation vnet set start. */
- Elf_Addr vnet_stop; /* Pre-relocation vnet set stop. */
- Elf_Addr vnet_base; /* Relocated vnet set address. */
+ Elf_Addr vnet_start; /* Pre-relocation vnet set start. */
+ Elf_Addr vnet_stop; /* Pre-relocation vnet set stop. */
+ Elf_Addr vnet_base; /* Relocated vnet set address. */
#endif
#ifdef GDB
- struct link_map gdb; /* hooks for gdb */
+ struct link_map gdb; /* hooks for gdb */
#endif
} *elf_file_t;
@@ -127,70 +127,71 @@ typedef struct elf_file {
static int link_elf_link_common_finish(linker_file_t);
static int link_elf_link_preload(linker_class_t cls,
- const char*, linker_file_t*);
+ const char *, linker_file_t *);
static int link_elf_link_preload_finish(linker_file_t);
-static int link_elf_load_file(linker_class_t, const char*, linker_file_t*);
-static int link_elf_lookup_symbol(linker_file_t, const char*,
- c_linker_sym_t*);
-static int link_elf_symbol_values(linker_file_t, c_linker_sym_t, linker_symval_t*);
-static int link_elf_search_symbol(linker_file_t, caddr_t value,
- c_linker_sym_t* sym, long* diffp);
+static int link_elf_load_file(linker_class_t, const char *,
+ linker_file_t *);
+static int link_elf_lookup_symbol(linker_file_t, const char *,
+ c_linker_sym_t *);
+static int link_elf_symbol_values(linker_file_t, c_linker_sym_t,
+ linker_symval_t *);
+static int link_elf_search_symbol(linker_file_t, caddr_t,
+ c_linker_sym_t *, long *);
static void link_elf_unload_file(linker_file_t);
static void link_elf_unload_preload(linker_file_t);
static int link_elf_lookup_set(linker_file_t, const char *,
- void ***, void ***, int *);
+ void ***, void ***, int *);
static int link_elf_each_function_name(linker_file_t,
- int (*)(const char *, void *),
- void *);
+ int (*)(const char *, void *), void *);
static int link_elf_each_function_nameval(linker_file_t,
- linker_function_nameval_callback_t,
- void *);
+ linker_function_nameval_callback_t, void *);
static void link_elf_reloc_local(linker_file_t);
static long link_elf_symtab_get(linker_file_t, const Elf_Sym **);
static long link_elf_strtab_get(linker_file_t, caddr_t *);
-static Elf_Addr elf_lookup(linker_file_t lf, Elf_Size symidx, int deps);
+static Elf_Addr elf_lookup(linker_file_t, Elf_Size, int);
static kobj_method_t link_elf_methods[] = {
- KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
- KOBJMETHOD(linker_symbol_values, link_elf_symbol_values),
- KOBJMETHOD(linker_search_symbol, link_elf_search_symbol),
- KOBJMETHOD(linker_unload, link_elf_unload_file),
- KOBJMETHOD(linker_load_file, link_elf_load_file),
- KOBJMETHOD(linker_link_preload, link_elf_link_preload),
- KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
- KOBJMETHOD(linker_lookup_set, link_elf_lookup_set),
- KOBJMETHOD(linker_each_function_name, link_elf_each_function_name),
- KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
- KOBJMETHOD(linker_ctf_get, link_elf_ctf_get),
- KOBJMETHOD(linker_symtab_get, link_elf_symtab_get),
- KOBJMETHOD(linker_strtab_get, link_elf_strtab_get),
- { 0, 0 }
+ KOBJMETHOD(linker_lookup_symbol, link_elf_lookup_symbol),
+ KOBJMETHOD(linker_symbol_values, link_elf_symbol_values),
+ KOBJMETHOD(linker_search_symbol, link_elf_search_symbol),
+ KOBJMETHOD(linker_unload, link_elf_unload_file),
+ KOBJMETHOD(linker_load_file, link_elf_load_file),
+ KOBJMETHOD(linker_link_preload, link_elf_link_preload),
+ KOBJMETHOD(linker_link_preload_finish, link_elf_link_preload_finish),
+ KOBJMETHOD(linker_lookup_set, link_elf_lookup_set),
+ KOBJMETHOD(linker_each_function_name, link_elf_each_function_name),
+ KOBJMETHOD(linker_each_function_nameval, link_elf_each_function_nameval),
+ KOBJMETHOD(linker_ctf_get, link_elf_ctf_get),
+ KOBJMETHOD(linker_symtab_get, link_elf_symtab_get),
+ KOBJMETHOD(linker_strtab_get, link_elf_strtab_get),
+ { 0, 0 }
};
static struct linker_class link_elf_class = {
#if ELF_TARG_CLASS == ELFCLASS32
- "elf32",
+ "elf32",
#else
- "elf64",
+ "elf64",
#endif
- link_elf_methods, sizeof(struct elf_file)
+ link_elf_methods, sizeof(struct elf_file)
};
-static int parse_dynamic(elf_file_t ef);
-static int relocate_file(elf_file_t ef);
-static int link_elf_preload_parse_symbols(elf_file_t ef);
+static int parse_dynamic(elf_file_t);
+static int relocate_file(elf_file_t);
+static int link_elf_preload_parse_symbols(elf_file_t);
#ifdef GDB
-static void r_debug_state(struct r_debug *dummy_one,
- struct link_map *dummy_two);
+static void r_debug_state(struct r_debug *, struct link_map *);
/*
* A list of loaded modules for GDB to use for loading symbols.
*/
struct r_debug r_debug;
-#define GDB_STATE(s) r_debug.r_state = s; r_debug_state(NULL, NULL);
+#define GDB_STATE(s) do { \
+ r_debug.r_state = s; r_debug_state(NULL, NULL); \
+} while (0)
/*
* Function for the debugger to set a breakpoint on to gain control.
@@ -204,35 +205,37 @@ r_debug_state(struct r_debug *dummy_one __unused,
static void
link_elf_add_gdb(struct link_map *l)
{
- struct link_map *prev;
-
- l->l_next = NULL;
-
- if (r_debug.r_map == NULL) {
- /* Add first. */
- l->l_prev = NULL;
- r_debug.r_map = l;
- } else {
- /* Append to list. */
- for (prev = r_debug.r_map; prev->l_next != NULL; prev = prev->l_next)
- ;
- l->l_prev = prev;
- prev->l_next = l;
- }
+ struct link_map *prev;
+
+ l->l_next = NULL;
+
+ if (r_debug.r_map == NULL) {
+ /* Add first. */
+ l->l_prev = NULL;
+ r_debug.r_map = l;
+ } else {
+ /* Append to list. */
+ for (prev = r_debug.r_map;
+ prev->l_next != NULL;
+ prev = prev->l_next)
+ ;
+ l->l_prev = prev;
+ prev->l_next = l;
+ }
}
static void
link_elf_delete_gdb(struct link_map *l)
{
- if (l->l_prev == NULL) {
- /* Remove first. */
- if ((r_debug.r_map = l->l_next) != NULL)
- l->l_next->l_prev = NULL;
- } else {
- /* Remove any but first. */
- if ((l->l_prev->l_next = l->l_next) != NULL)
- l->l_next->l_prev = l->l_prev;
- }
+ if (l->l_prev == NULL) {
+ /* Remove first. */
+ if ((r_debug.r_map = l->l_next) != NULL)
+ l->l_next->l_prev = NULL;
+ } else {
+ /* Remove any but first. */
+ if ((l->l_prev->l_next = l->l_next) != NULL)
+ l->l_next->l_prev = l->l_prev;
+ }
}
#endif /* GDB */
@@ -262,85 +265,86 @@ static int
link_elf_link_common_finish(linker_file_t lf)
{
#ifdef GDB
- elf_file_t ef = (elf_file_t)lf;
- char *newfilename;
+ elf_file_t ef = (elf_file_t)lf;
+ char *newfilename;
#endif
- int error;
+ int error;
- /* Notify MD code that a module is being loaded. */
- error = elf_cpu_load_file(lf);
- if (error)
- return (error);
+ /* Notify MD code that a module is being loaded. */
+ error = elf_cpu_load_file(lf);
+ if (error != 0)
+ return (error);
#ifdef GDB
- GDB_STATE(RT_ADD);
- ef->gdb.l_addr = lf->address;
- newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, M_WAITOK);
- strcpy(newfilename, lf->filename);
- ef->gdb.l_name = newfilename;
- ef->gdb.l_ld = ef->dynamic;
- link_elf_add_gdb(&ef->gdb);
- GDB_STATE(RT_CONSISTENT);
+ GDB_STATE(RT_ADD);
+ ef->gdb.l_addr = lf->address;
+ newfilename = malloc(strlen(lf->filename) + 1, M_LINKER, M_WAITOK);
+ strcpy(newfilename, lf->filename);
+ ef->gdb.l_name = newfilename;
+ ef->gdb.l_ld = ef->dynamic;
+ link_elf_add_gdb(&ef->gdb);
+ GDB_STATE(RT_CONSISTENT);
#endif
- return (0);
+ return (0);
}
static void
link_elf_init(void* arg)
{
- Elf_Dyn *dp;
- caddr_t modptr, baseptr, sizeptr;
- elf_file_t ef;
- char *modname;
-
- linker_add_class(&link_elf_class);
-
- dp = (Elf_Dyn*) &_DYNAMIC;
- modname = NULL;
- modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
- if (modptr == NULL)
- modptr = preload_search_by_type("elf kernel");
- if (modptr)
- modname = (char *)preload_search_info(modptr, MODINFO_NAME);
- if (modname == NULL)
- modname = "kernel";
- linker_kernel_file = linker_make_file(modname, &link_elf_class);
- if (linker_kernel_file == NULL)
- panic("link_elf_init: Can't create linker structures for kernel");
-
- ef = (elf_file_t) linker_kernel_file;
- ef->preloaded = 1;
- ef->address = 0;
+ Elf_Dyn *dp;
+ caddr_t modptr, baseptr, sizeptr;
+ elf_file_t ef;
+ char *modname;
+
+ linker_add_class(&link_elf_class);
+
+ dp = (Elf_Dyn *)&_DYNAMIC;
+ modname = NULL;
+ modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel");
+ if (modptr == NULL)
+ modptr = preload_search_by_type("elf kernel");
+ if (modptr != NULL)
+ modname = (char *)preload_search_info(modptr, MODINFO_NAME);
+ if (modname == NULL)
+ modname = "kernel";
+ linker_kernel_file = linker_make_file(modname, &link_elf_class);
+ if (linker_kernel_file == NULL)
+ panic("%s: Can't create linker structures for kernel",
+ __func__);
+
+ ef = (elf_file_t) linker_kernel_file;
+ ef->preloaded = 1;
+ ef->address = 0;
#ifdef SPARSE_MAPPING
- ef->object = 0;
+ ef->object = 0;
#endif
- ef->dynamic = dp;
-
- if (dp)
- parse_dynamic(ef);
- linker_kernel_file->address = (caddr_t) KERNBASE;
- linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
-
- if (modptr) {
- ef->modptr = modptr;
- baseptr = preload_search_info(modptr, MODINFO_ADDR);
- if (baseptr)
- linker_kernel_file->address = *(caddr_t *)baseptr;
- sizeptr = preload_search_info(modptr, MODINFO_SIZE);
- if (sizeptr)
- linker_kernel_file->size = *(size_t *)sizeptr;
- }
- (void)link_elf_preload_parse_symbols(ef);
+ ef->dynamic = dp;
+
+ if (dp != NULL)
+ parse_dynamic(ef);
+ linker_kernel_file->address = (caddr_t) KERNBASE;
+ linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
+
+ if (modptr != NULL) {
+ ef->modptr = modptr;
+ baseptr = preload_search_info(modptr, MODINFO_ADDR);
+ if (baseptr != NULL)
+ linker_kernel_file->address = *(caddr_t *)baseptr;
+ sizeptr = preload_search_info(modptr, MODINFO_SIZE);
+ if (sizeptr != NULL)
+ linker_kernel_file->size = *(size_t *)sizeptr;
+ }
+ (void)link_elf_preload_parse_symbols(ef);
#ifdef GDB
- r_debug.r_map = NULL;
- r_debug.r_brk = r_debug_state;
- r_debug.r_state = RT_CONSISTENT;
+ r_debug.r_map = NULL;
+ r_debug.r_brk = r_debug_state;
+ r_debug.r_state = RT_CONSISTENT;
#endif
- (void)link_elf_link_common_finish(linker_kernel_file);
- linker_kernel_file->flags |= LINKER_FILE_LINKED;
+ (void)link_elf_link_common_finish(linker_kernel_file);
+ linker_kernel_file->flags |= LINKER_FILE_LINKED;
}
SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_THIRD, link_elf_init, 0);
@@ -348,795 +352,807 @@ SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_THIRD, link_elf_init, 0);
static int
link_elf_preload_parse_symbols(elf_file_t ef)
{
- caddr_t pointer;
- caddr_t ssym, esym, base;
- caddr_t strtab;
- int strcnt;
- Elf_Sym* symtab;
- int symcnt;
-
- if (ef->modptr == NULL)
- return 0;
- pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_SSYM);
- if (pointer == NULL)
- return 0;
- ssym = *(caddr_t *)pointer;
- pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_ESYM);
- if (pointer == NULL)
- return 0;
- esym = *(caddr_t *)pointer;
-
- base = ssym;
-
- symcnt = *(long *)base;
- base += sizeof(long);
- symtab = (Elf_Sym *)base;
- base += roundup(symcnt, sizeof(long));
-
- if (base > esym || base < ssym) {
- printf("Symbols are corrupt!\n");
- return EINVAL;
- }
+ caddr_t pointer;
+ caddr_t ssym, esym, base;
+ caddr_t strtab;
+ int strcnt;
+ Elf_Sym *symtab;
+ int symcnt;
+
+ if (ef->modptr == NULL)
+ return (0);
+ pointer = preload_search_info(ef->modptr,
+ MODINFO_METADATA | MODINFOMD_SSYM);
+ if (pointer == NULL)
+ return (0);
+ ssym = *(caddr_t *)pointer;
+ pointer = preload_search_info(ef->modptr,
+ MODINFO_METADATA | MODINFOMD_ESYM);
+ if (pointer == NULL)
+ return (0);
+ esym = *(caddr_t *)pointer;
- strcnt = *(long *)base;
- base += sizeof(long);
- strtab = base;
- base += roundup(strcnt, sizeof(long));
+ base = ssym;
- if (base > esym || base < ssym) {
- printf("Symbols are corrupt!\n");
- return EINVAL;
- }
+ symcnt = *(long *)base;
+ base += sizeof(long);
+ symtab = (Elf_Sym *)base;
+ base += roundup(symcnt, sizeof(long));
+
+ if (base > esym || base < ssym) {
+ printf("Symbols are corrupt!\n");
+ return (EINVAL);
+ }
- ef->ddbsymtab = symtab;
- ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
- ef->ddbstrtab = strtab;
- ef->ddbstrcnt = strcnt;
+ strcnt = *(long *)base;
+ base += sizeof(long);
+ strtab = base;
+ base += roundup(strcnt, sizeof(long));
- return 0;
+ if (base > esym || base < ssym) {
+ printf("Symbols are corrupt!\n");
+ return (EINVAL);
+ }
+
+ ef->ddbsymtab = symtab;
+ ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
+ ef->ddbstrtab = strtab;
+ ef->ddbstrcnt = strcnt;
+
+ return (0);
}
static int
parse_dynamic(elf_file_t ef)
{
- Elf_Dyn *dp;
- int plttype = DT_REL;
-
- for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
- switch (dp->d_tag) {
- case DT_HASH:
- {
- /* From src/libexec/rtld-elf/rtld.c */
- const Elf_Hashelt *hashtab = (const Elf_Hashelt *)
- (ef->address + dp->d_un.d_ptr);
- ef->nbuckets = hashtab[0];
- ef->nchains = hashtab[1];
- ef->buckets = hashtab + 2;
- ef->chains = ef->buckets + ef->nbuckets;
- break;
- }
- case DT_STRTAB:
- ef->strtab = (caddr_t) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_STRSZ:
- ef->strsz = dp->d_un.d_val;
- break;
- case DT_SYMTAB:
- ef->symtab = (Elf_Sym*) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_SYMENT:
- if (dp->d_un.d_val != sizeof(Elf_Sym))
- return ENOEXEC;
- break;
- case DT_PLTGOT:
- ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_REL:
- ef->rel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_RELSZ:
- ef->relsize = dp->d_un.d_val;
- break;
- case DT_RELENT:
- if (dp->d_un.d_val != sizeof(Elf_Rel))
- return ENOEXEC;
- break;
- case DT_JMPREL:
- ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_PLTRELSZ:
- ef->pltrelsize = dp->d_un.d_val;
- break;
- case DT_RELA:
- ef->rela = (const Elf_Rela *) (ef->address + dp->d_un.d_ptr);
- break;
- case DT_RELASZ:
- ef->relasize = dp->d_un.d_val;
- break;
- case DT_RELAENT:
- if (dp->d_un.d_val != sizeof(Elf_Rela))
- return ENOEXEC;
- break;
- case DT_PLTREL:
- plttype = dp->d_un.d_val;
- if (plttype != DT_REL && plttype != DT_RELA)
- return ENOEXEC;
- break;
+ Elf_Dyn *dp;
+ int plttype = DT_REL;
+
+ for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
+ switch (dp->d_tag) {
+ case DT_HASH:
+ {
+ /* From src/libexec/rtld-elf/rtld.c */
+ const Elf_Hashelt *hashtab = (const Elf_Hashelt *)
+ (ef->address + dp->d_un.d_ptr);
+ ef->nbuckets = hashtab[0];
+ ef->nchains = hashtab[1];
+ ef->buckets = hashtab + 2;
+ ef->chains = ef->buckets + ef->nbuckets;
+ break;
+ }
+ case DT_STRTAB:
+ ef->strtab = (caddr_t) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_STRSZ:
+ ef->strsz = dp->d_un.d_val;
+ break;
+ case DT_SYMTAB:
+ ef->symtab = (Elf_Sym*) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_SYMENT:
+ if (dp->d_un.d_val != sizeof(Elf_Sym))
+ return (ENOEXEC);
+ break;
+ case DT_PLTGOT:
+ ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_REL:
+ ef->rel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_RELSZ:
+ ef->relsize = dp->d_un.d_val;
+ break;
+ case DT_RELENT:
+ if (dp->d_un.d_val != sizeof(Elf_Rel))
+ return (ENOEXEC);
+ break;
+ case DT_JMPREL:
+ ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_PLTRELSZ:
+ ef->pltrelsize = dp->d_un.d_val;
+ break;
+ case DT_RELA:
+ ef->rela = (const Elf_Rela *) (ef->address + dp->d_un.d_ptr);
+ break;
+ case DT_RELASZ:
+ ef->relasize = dp->d_un.d_val;
+ break;
+ case DT_RELAENT:
+ if (dp->d_un.d_val != sizeof(Elf_Rela))
+ return (ENOEXEC);
+ break;
+ case DT_PLTREL:
+ plttype = dp->d_un.d_val;
+ if (plttype != DT_REL && plttype != DT_RELA)
+ return (ENOEXEC);
+ break;
#ifdef GDB
- case DT_DEBUG:
- dp->d_un.d_ptr = (Elf_Addr) &r_debug;
- break;
+ case DT_DEBUG:
+ dp->d_un.d_ptr = (Elf_Addr)&r_debug;
+ break;
#endif
+ }
}
- }
- if (plttype == DT_RELA) {
- ef->pltrela = (const Elf_Rela *) ef->pltrel;
- ef->pltrel = NULL;
- ef->pltrelasize = ef->pltrelsize;
- ef->pltrelsize = 0;
- }
+ if (plttype == DT_RELA) {
+ ef->pltrela = (const Elf_Rela *)ef->pltrel;
+ ef->pltrel = NULL;
+ ef->pltrelasize = ef->pltrelsize;
+ ef->pltrelsize = 0;
+ }
- ef->ddbsymtab = ef->symtab;
- ef->ddbsymcnt = ef->nchains;
- ef->ddbstrtab = ef->strtab;
- ef->ddbstrcnt = ef->strsz;
+ ef->ddbsymtab = ef->symtab;
+ ef->ddbsymcnt = ef->nchains;
+ ef->ddbstrtab = ef->strtab;
+ ef->ddbstrcnt = ef->strsz;
- return 0;
+ return (0);
}
static int
parse_dpcpu(elf_file_t ef)
{
- int count;
- int error;
-
- ef->pcpu_start = 0;
- ef->pcpu_stop = 0;
- error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start,
- (void ***)&ef->pcpu_stop, &count);
- /* Error just means there is no pcpu set to relocate. */
- if (error)
- return (0);
- count *= sizeof(void *);
- /*
- * Allocate space in the primary pcpu area. Copy in our initialization
- * from the data section and then initialize all per-cpu storage from
- * that.
- */
- ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(count);
- if (ef->pcpu_base == (Elf_Addr)NULL)
- return (ENOSPC);
- memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, count);
- dpcpu_copy((void *)ef->pcpu_base, count);
-
- return (0);
+ int count;
+ int error;
+
+ ef->pcpu_start = 0;
+ ef->pcpu_stop = 0;
+ error = link_elf_lookup_set(&ef->lf, "pcpu", (void ***)&ef->pcpu_start,
+ (void ***)&ef->pcpu_stop, &count);
+ /* Error just means there is no pcpu set to relocate. */
+ if (error != 0)
+ return (0);
+ count *= sizeof(void *);
+ /*
+ * Allocate space in the primary pcpu area. Copy in our
+ * initialization from the data section and then initialize
+ * all per-cpu storage from that.
+ */
+ ef->pcpu_base = (Elf_Addr)(uintptr_t)dpcpu_alloc(count);
+ if (ef->pcpu_base == 0)
+ return (ENOSPC);
+ memcpy((void *)ef->pcpu_base, (void *)ef->pcpu_start, count);
+ dpcpu_copy((void *)ef->pcpu_base, count);
+
+ return (0);
}
#ifdef VIMAGE
static int
parse_vnet(elf_file_t ef)
{
- int count;
- int error;
-
- ef->vnet_start = 0;
- ef->vnet_stop = 0;
- error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
- (void ***)&ef->vnet_stop, &count);
- /* Error just means there is no vnet data set to relocate. */
- if (error)
- return (0);
- count *= sizeof(void *);
- /*
- * Allocate space in the primary vnet area. Copy in our initialization
- * from the data section and then initialize all per-vnet storage from
- * that.
- */
- ef->vnet_base = (Elf_Addr)(uintptr_t)vnet_data_alloc(count);
- if (ef->vnet_base == (Elf_Addr)NULL)
- return (ENOSPC);
- memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, count);
- vnet_data_copy((void *)ef->vnet_base, count);
-
- return (0);
+ int count;
+ int error;
+
+ ef->vnet_start = 0;
+ ef->vnet_stop = 0;
+ error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start,
+ (void ***)&ef->vnet_stop, &count);
+ /* Error just means there is no vnet data set to relocate. */
+ if (error != 0)
+ return (0);
+ count *= sizeof(void *);
+ /*
+ * Allocate space in the primary vnet area. Copy in our
+ * initialization from the data section and then initialize
+ * all per-vnet storage from that.
+ */
+ ef->vnet_base = (Elf_Addr)(uintptr_t)vnet_data_alloc(count);
+ if (ef->vnet_base == 0)
+ return (ENOSPC);
+ memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, count);
+ vnet_data_copy((void *)ef->vnet_base, count);
+
+ return (0);
}
#endif
static int
link_elf_link_preload(linker_class_t cls,
- const char* filename, linker_file_t *result)
+ const char* filename, linker_file_t *result)
{
- caddr_t modptr, baseptr, sizeptr, dynptr;
- char *type;
- elf_file_t ef;
- linker_file_t lf;
- int error;
- vm_offset_t dp;
-
- /* Look to see if we have the file preloaded */
- modptr = preload_search_by_name(filename);
- if (modptr == NULL)
- return ENOENT;
-
- type = (char *)preload_search_info(modptr, MODINFO_TYPE);
- baseptr = preload_search_info(modptr, MODINFO_ADDR);
- sizeptr = preload_search_info(modptr, MODINFO_SIZE);
- dynptr = preload_search_info(modptr, MODINFO_METADATA|MODINFOMD_DYNAMIC);
- if (type == NULL ||
- (strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE) " module") != 0 &&
- strcmp(type, "elf module") != 0))
- return (EFTYPE);
- if (baseptr == NULL || sizeptr == NULL || dynptr == NULL)
- return (EINVAL);
-
- lf = linker_make_file(filename, &link_elf_class);
- if (lf == NULL) {
- return ENOMEM;
- }
-
- ef = (elf_file_t) lf;
- ef->preloaded = 1;
- ef->modptr = modptr;
- ef->address = *(caddr_t *)baseptr;
+ caddr_t modptr, baseptr, sizeptr, dynptr;
+ char *type;
+ elf_file_t ef;
+ linker_file_t lf;
+ int error;
+ vm_offset_t dp;
+
+ /* Look to see if we have the file preloaded */
+ modptr = preload_search_by_name(filename);
+ if (modptr == NULL)
+ return (ENOENT);
+
+ type = (char *)preload_search_info(modptr, MODINFO_TYPE);
+ baseptr = preload_search_info(modptr, MODINFO_ADDR);
+ sizeptr = preload_search_info(modptr, MODINFO_SIZE);
+ dynptr = preload_search_info(modptr,
+ MODINFO_METADATA | MODINFOMD_DYNAMIC);
+ if (type == NULL ||
+ (strcmp(type, "elf" __XSTRING(__ELF_WORD_SIZE) " module") != 0 &&
+ strcmp(type, "elf module") != 0))
+ return (EFTYPE);
+ if (baseptr == NULL || sizeptr == NULL || dynptr == NULL)
+ return (EINVAL);
+
+ lf = linker_make_file(filename, &link_elf_class);
+ if (lf == NULL)
+ return (ENOMEM);
+
+ ef = (elf_file_t) lf;
+ ef->preloaded = 1;
+ ef->modptr = modptr;
+ ef->address = *(caddr_t *)baseptr;
#ifdef SPARSE_MAPPING
- ef->object = 0;
+ ef->object = 0;
#endif
- dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
- ef->dynamic = (Elf_Dyn *)dp;
- lf->address = ef->address;
- lf->size = *(size_t *)sizeptr;
-
- error = parse_dynamic(ef);
- if (error == 0)
- error = parse_dpcpu(ef);
+ dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
+ ef->dynamic = (Elf_Dyn *)dp;
+ lf->address = ef->address;
+ lf->size = *(size_t *)sizeptr;
+
+ error = parse_dynamic(ef);
+ if (error == 0)
+ error = parse_dpcpu(ef);
#ifdef VIMAGE
- if (error == 0)
- error = parse_vnet(ef);
+ if (error == 0)
+ error = parse_vnet(ef);
#endif
- if (error) {
- linker_file_unload(lf, LINKER_UNLOAD_FORCE);
- return error;
- }
- link_elf_reloc_local(lf);
- *result = lf;
- return (0);
+ if (error != 0) {
+ linker_file_unload(lf, LINKER_UNLOAD_FORCE);
+ return (error);
+ }
+ link_elf_reloc_local(lf);
+ *result = lf;
+ return (0);
}
static int
link_elf_link_preload_finish(linker_file_t lf)
{
- elf_file_t ef;
- int error;
+ elf_file_t ef;
+ int error;
- ef = (elf_file_t) lf;
+ ef = (elf_file_t) lf;
#if 0 /* this will be more trouble than it's worth for now */
- for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
- if (dp->d_tag != DT_NEEDED)
- continue;
- modname = ef->strtab + dp->d_un.d_val;
- error = linker_load_module(modname, lf);
- if (error)
- goto out;
+ for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
+ if (dp->d_tag != DT_NEEDED)
+ continue;
+ modname = ef->strtab + dp->d_un.d_val;
+ error = linker_load_module(modname, lf);
+ if (error != 0)
+ goto out;
}
#endif
- error = relocate_file(ef);
- if (error)
- return error;
- (void)link_elf_preload_parse_symbols(ef);
+ error = relocate_file(ef);
+ if (error != 0)
+ return (error);
+ (void)link_elf_preload_parse_symbols(ef);
- return (link_elf_link_common_finish(lf));
+ return (link_elf_link_common_finish(lf));
}
static int
link_elf_load_file(linker_class_t cls, const char* filename,
- linker_file_t* result)
+ linker_file_t* result)
{
- struct nameidata nd;
- struct thread* td = curthread; /* XXX */
- Elf_Ehdr *hdr;
- caddr_t firstpage;
- int nbytes, i;
- Elf_Phdr *phdr;
- Elf_Phdr *phlimit;
- Elf_Phdr *segs[MAXSEGS];
- int nsegs;
- Elf_Phdr *phdyn;
- Elf_Phdr *phphdr;
- caddr_t mapbase;
- size_t mapsize;
- Elf_Off base_offset;
- Elf_Addr base_vaddr;
- Elf_Addr base_vlimit;
- int error = 0;
- int resid, flags;
- elf_file_t ef;
- linker_file_t lf;
- Elf_Shdr *shdr;
- int symtabindex;
- int symstrindex;
- int symcnt;
- int strcnt;
- int vfslocked;
-
- shdr = NULL;
- lf = NULL;
-
- NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
- flags = FREAD;
- error = vn_open(&nd, &flags, 0, NULL);
- if (error)
- return error;
- vfslocked = NDHASGIANT(&nd);
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if (nd.ni_vp->v_type != VREG) {
- error = ENOEXEC;
- firstpage = NULL;
- goto out;
- }
+ struct nameidata nd;
+ struct thread* td = curthread; /* XXX */
+ Elf_Ehdr *hdr;
+ caddr_t firstpage;
+ int nbytes, i;
+ Elf_Phdr *phdr;
+ Elf_Phdr *phlimit;
+ Elf_Phdr *segs[MAXSEGS];
+ int nsegs;
+ Elf_Phdr *phdyn;
+ Elf_Phdr *phphdr;
+ caddr_t mapbase;
+ size_t mapsize;
+ Elf_Off base_offset;
+ Elf_Addr base_vaddr;
+ Elf_Addr base_vlimit;
+ int error = 0;
+ int resid, flags;
+ elf_file_t ef;
+ linker_file_t lf;
+ Elf_Shdr *shdr;
+ int symtabindex;
+ int symstrindex;
+ int symcnt;
+ int strcnt;
+ int vfslocked;
+
+ shdr = NULL;
+ lf = NULL;
+
+ NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
+ flags = FREAD;
+ error = vn_open(&nd, &flags, 0, NULL);
+ if (error != 0)
+ return (error);
+ vfslocked = NDHASGIANT(&nd);
+ NDFREE(&nd, NDF_ONLY_PNBUF);
+ if (nd.ni_vp->v_type != VREG) {
+ error = ENOEXEC;
+ firstpage = NULL;
+ goto out;
+ }
#ifdef MAC
- error = mac_kld_check_load(curthread->td_ucred, nd.ni_vp);
- if (error) {
- firstpage = NULL;
- goto out;
- }
+ error = mac_kld_check_load(curthread->td_ucred, nd.ni_vp);
+ if (error != 0) {
+ firstpage = NULL;
+ goto out;
+ }
#endif
- /*
- * Read the elf header from the file.
- */
- firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
- if (firstpage == NULL) {
- error = ENOMEM;
- goto out;
- }
- hdr = (Elf_Ehdr *)firstpage;
- error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
- UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
- &resid, td);
- nbytes = PAGE_SIZE - resid;
- if (error)
- goto out;
-
- if (!IS_ELF(*hdr)) {
- error = ENOEXEC;
- goto out;
- }
+ /*
+ * Read the elf header from the file.
+ */
+ firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
+ if (firstpage == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+ hdr = (Elf_Ehdr *)firstpage;
+ error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
+ UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+ &resid, td);
+ nbytes = PAGE_SIZE - resid;
+ if (error != 0)
+ goto out;
- if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
- || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
- link_elf_error(filename, "Unsupported file layout");
- error = ENOEXEC;
- goto out;
- }
- if (hdr->e_ident[EI_VERSION] != EV_CURRENT
- || hdr->e_version != EV_CURRENT) {
- link_elf_error(filename, "Unsupported file version");
- error = ENOEXEC;
- goto out;
- }
- if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
- error = ENOSYS;
- goto out;
- }
- if (hdr->e_machine != ELF_TARG_MACH) {
- link_elf_error(filename, "Unsupported machine");
- error = ENOEXEC;
- goto out;
- }
+ if (!IS_ELF(*hdr)) {
+ error = ENOEXEC;
+ goto out;
+ }
- /*
- * We rely on the program header being in the first page. This is
- * not strictly required by the ABI specification, but it seems to
- * always true in practice. And, it simplifies things considerably.
- */
- if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
- (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
- (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
- link_elf_error(filename, "Unreadable program headers");
-
- /*
- * Scan the program header entries, and save key information.
- *
- * We rely on there being exactly two load segments, text and data,
- * in that order.
- */
- phdr = (Elf_Phdr *) (firstpage + hdr->e_phoff);
- phlimit = phdr + hdr->e_phnum;
- nsegs = 0;
- phdyn = NULL;
- phphdr = NULL;
- while (phdr < phlimit) {
- switch (phdr->p_type) {
-
- case PT_LOAD:
- if (nsegs == MAXSEGS) {
- link_elf_error(filename, "Too many sections");
+ if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS ||
+ hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
+ link_elf_error(filename, "Unsupported file layout");
+ error = ENOEXEC;
+ goto out;
+ }
+ if (hdr->e_ident[EI_VERSION] != EV_CURRENT ||
+ hdr->e_version != EV_CURRENT) {
+ link_elf_error(filename, "Unsupported file version");
+ error = ENOEXEC;
+ goto out;
+ }
+ if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
+ error = ENOSYS;
+ goto out;
+ }
+ if (hdr->e_machine != ELF_TARG_MACH) {
+ link_elf_error(filename, "Unsupported machine");
error = ENOEXEC;
goto out;
- }
- /*
- * XXX: We just trust they come in right order ??
- */
- segs[nsegs] = phdr;
- ++nsegs;
- break;
-
- case PT_PHDR:
- phphdr = phdr;
- break;
-
- case PT_DYNAMIC:
- phdyn = phdr;
- break;
-
- case PT_INTERP:
- error = ENOSYS;
- goto out;
}
- ++phdr;
- }
- if (phdyn == NULL) {
- link_elf_error(filename, "Object is not dynamically-linked");
- error = ENOEXEC;
- goto out;
- }
- if (nsegs == 0) {
- link_elf_error(filename, "No sections");
- error = ENOEXEC;
- goto out;
- }
+ /*
+ * We rely on the program header being in the first page.
+ * This is not strictly required by the ABI specification, but
+ * it seems to always true in practice. And, it simplifies
+ * things considerably.
+ */
+ if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
+ (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
+ (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
+ link_elf_error(filename, "Unreadable program headers");
- /*
- * Allocate the entire address space of the object, to stake out our
- * contiguous region, and to establish the base address for relocation.
- */
- base_offset = trunc_page(segs[0]->p_offset);
- base_vaddr = trunc_page(segs[0]->p_vaddr);
- base_vlimit = round_page(segs[nsegs - 1]->p_vaddr +
- segs[nsegs - 1]->p_memsz);
- mapsize = base_vlimit - base_vaddr;
-
- lf = linker_make_file(filename, &link_elf_class);
- if (!lf) {
- error = ENOMEM;
- goto out;
- }
+ /*
+ * Scan the program header entries, and save key information.
+ *
+ * We rely on there being exactly two load segments, text and data,
+ * in that order.
+ */
+ phdr = (Elf_Phdr *) (firstpage + hdr->e_phoff);
+ phlimit = phdr + hdr->e_phnum;
+ nsegs = 0;
+ phdyn = NULL;
+ phphdr = NULL;
+ while (phdr < phlimit) {
+ switch (phdr->p_type) {
+ case PT_LOAD:
+ if (nsegs == MAXSEGS) {
+ link_elf_error(filename, "Too many sections");
+ error = ENOEXEC;
+ goto out;
+ }
+ /*
+ * XXX: We just trust they come in right order ??
+ */
+ segs[nsegs] = phdr;
+ ++nsegs;
+ break;
+
+ case PT_PHDR:
+ phphdr = phdr;
+ break;
+
+ case PT_DYNAMIC:
+ phdyn = phdr;
+ break;
+
+ case PT_INTERP:
+ error = ENOSYS;
+ goto out;
+ }
- ef = (elf_file_t) lf;
-#ifdef SPARSE_MAPPING
- ef->object = vm_object_allocate(OBJT_DEFAULT, mapsize >> PAGE_SHIFT);
- if (ef->object == NULL) {
- error = ENOMEM;
- goto out;
- }
- ef->address = (caddr_t) vm_map_min(kernel_map);
- error = vm_map_find(kernel_map, ef->object, 0,
- (vm_offset_t *) &ef->address,
- mapsize, 1,
- VM_PROT_ALL, VM_PROT_ALL, 0);
- if (error) {
- vm_object_deallocate(ef->object);
- ef->object = 0;
- goto out;
- }
-#else
- ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
- if (!ef->address) {
- error = ENOMEM;
- goto out;
- }
-#endif
- mapbase = ef->address;
+ ++phdr;
+ }
+ if (phdyn == NULL) {
+ link_elf_error(filename, "Object is not dynamically-linked");
+ error = ENOEXEC;
+ goto out;
+ }
+ if (nsegs == 0) {
+ link_elf_error(filename, "No sections");
+ error = ENOEXEC;
+ goto out;
+ }
- /*
- * Read the text and data sections and zero the bss.
- */
- for (i = 0; i < nsegs; i++) {
- caddr_t segbase = mapbase + segs[i]->p_vaddr - base_vaddr;
- error = vn_rdwr(UIO_READ, nd.ni_vp,
- segbase, segs[i]->p_filesz, segs[i]->p_offset,
- UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
- &resid, td);
- if (error) {
- goto out;
+ /*
+ * Allocate the entire address space of the object, to stake
+ * out our contiguous region, and to establish the base
+ * address for relocation.
+ */
+ base_offset = trunc_page(segs[0]->p_offset);
+ base_vaddr = trunc_page(segs[0]->p_vaddr);
+ base_vlimit = round_page(segs[nsegs - 1]->p_vaddr +
+ segs[nsegs - 1]->p_memsz);
+ mapsize = base_vlimit - base_vaddr;
+
+ lf = linker_make_file(filename, &link_elf_class);
+ if (lf == NULL) {
+ error = ENOMEM;
+ goto out;
}
- bzero(segbase + segs[i]->p_filesz,
- segs[i]->p_memsz - segs[i]->p_filesz);
+ ef = (elf_file_t) lf;
#ifdef SPARSE_MAPPING
+ ef->object = vm_object_allocate(OBJT_DEFAULT, mapsize >> PAGE_SHIFT);
+ if (ef->object == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+ ef->address = (caddr_t) vm_map_min(kernel_map);
+ error = vm_map_find(kernel_map, ef->object, 0,
+ (vm_offset_t *) &ef->address, mapsize, 1,
+ VM_PROT_ALL, VM_PROT_ALL, 0);
+ if (error != 0) {
+ vm_object_deallocate(ef->object);
+ ef->object = 0;
+ goto out;
+ }
+#else
+ ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
+ if (ef->address == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+#endif
+ mapbase = ef->address;
+
/*
- * Wire down the pages
+ * Read the text and data sections and zero the bss.
*/
- error = vm_map_wire(kernel_map,
+ for (i = 0; i < nsegs; i++) {
+ caddr_t segbase = mapbase + segs[i]->p_vaddr - base_vaddr;
+ error = vn_rdwr(UIO_READ, nd.ni_vp,
+ segbase, segs[i]->p_filesz, segs[i]->p_offset,
+ UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+ &resid, td);
+ if (error != 0)
+ goto out;
+ bzero(segbase + segs[i]->p_filesz,
+ segs[i]->p_memsz - segs[i]->p_filesz);
+
+#ifdef SPARSE_MAPPING
+ /*
+ * Wire down the pages
+ */
+ error = vm_map_wire(kernel_map,
(vm_offset_t) segbase,
(vm_offset_t) segbase + segs[i]->p_memsz,
VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES);
- if (error != KERN_SUCCESS) {
- error = ENOMEM;
- goto out;
- }
+ if (error != KERN_SUCCESS) {
+ error = ENOMEM;
+ goto out;
+ }
#endif
- }
+ }
#ifdef GPROF
- /* Update profiling information with the new text segment. */
- mtx_lock(&Giant);
- kmupetext((uintfptr_t)(mapbase + segs[0]->p_vaddr - base_vaddr +
- segs[0]->p_memsz));
- mtx_unlock(&Giant);
+ /* Update profiling information with the new text segment. */
+ mtx_lock(&Giant);
+ kmupetext((uintfptr_t)(mapbase + segs[0]->p_vaddr - base_vaddr +
+ segs[0]->p_memsz));
+ mtx_unlock(&Giant);
#endif
- ef->dynamic = (Elf_Dyn *) (mapbase + phdyn->p_vaddr - base_vaddr);
+ ef->dynamic = (Elf_Dyn *) (mapbase + phdyn->p_vaddr - base_vaddr);
- lf->address = ef->address;
- lf->size = mapsize;
+ lf->address = ef->address;
+ lf->size = mapsize;
- error = parse_dynamic(ef);
- if (error)
- goto out;
- error = parse_dpcpu(ef);
- if (error)
- goto out;
+ error = parse_dynamic(ef);
+ if (error != 0)
+ goto out;
+ error = parse_dpcpu(ef);
+ if (error != 0)
+ goto out;
#ifdef VIMAGE
- error = parse_vnet(ef);
- if (error)
- goto out;
+ error = parse_vnet(ef);
+ if (error != 0)
+ goto out;
#endif
- link_elf_reloc_local(lf);
+ link_elf_reloc_local(lf);
- VOP_UNLOCK(nd.ni_vp, 0);
- error = linker_load_dependencies(lf);
- vn_lock(nd.ni_vp, LK_EXCLUSIVE | LK_RETRY);
- if (error)
- goto out;
+ VOP_UNLOCK(nd.ni_vp, 0);
+ error = linker_load_dependencies(lf);
+ vn_lock(nd.ni_vp, LK_EXCLUSIVE | LK_RETRY);
+ if (error != 0)
+ goto out;
#if 0 /* this will be more trouble than it's worth for now */
- for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
- if (dp->d_tag != DT_NEEDED)
- continue;
- modname = ef->strtab + dp->d_un.d_val;
- error = linker_load_module(modname, lf);
- if (error)
- goto out;
+ for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
+ if (dp->d_tag != DT_NEEDED)
+ continue;
+ modname = ef->strtab + dp->d_un.d_val;
+ error = linker_load_module(modname, lf);
+ if (error != 0)
+ goto out;
}
#endif
- error = relocate_file(ef);
- if (error)
- goto out;
-
- /* Try and load the symbol table if it's present. (you can strip it!) */
- nbytes = hdr->e_shnum * hdr->e_shentsize;
- if (nbytes == 0 || hdr->e_shoff == 0)
- goto nosyms;
- shdr = malloc(nbytes, M_LINKER, M_WAITOK | M_ZERO);
- if (shdr == NULL) {
- error = ENOMEM;
- goto out;
- }
- error = vn_rdwr(UIO_READ, nd.ni_vp,
- (caddr_t)shdr, nbytes, hdr->e_shoff,
- UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
- &resid, td);
- if (error)
- goto out;
- symtabindex = -1;
- symstrindex = -1;
- for (i = 0; i < hdr->e_shnum; i++) {
- if (shdr[i].sh_type == SHT_SYMTAB) {
- symtabindex = i;
- symstrindex = shdr[i].sh_link;
+ error = relocate_file(ef);
+ if (error != 0)
+ goto out;
+
+ /*
+ * Try and load the symbol table if it's present. (you can
+ * strip it!)
+ */
+ nbytes = hdr->e_shnum * hdr->e_shentsize;
+ if (nbytes == 0 || hdr->e_shoff == 0)
+ goto nosyms;
+ shdr = malloc(nbytes, M_LINKER, M_WAITOK | M_ZERO);
+ if (shdr == NULL) {
+ error = ENOMEM;
+ goto out;
}
- }
- if (symtabindex < 0 || symstrindex < 0)
- goto nosyms;
+ error = vn_rdwr(UIO_READ, nd.ni_vp,
+ (caddr_t)shdr, nbytes, hdr->e_shoff,
+ UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+ &resid, td);
+ if (error != 0)
+ goto out;
+ symtabindex = -1;
+ symstrindex = -1;
+ for (i = 0; i < hdr->e_shnum; i++) {
+ if (shdr[i].sh_type == SHT_SYMTAB) {
+ symtabindex = i;
+ symstrindex = shdr[i].sh_link;
+ }
+ }
+ if (symtabindex < 0 || symstrindex < 0)
+ goto nosyms;
- symcnt = shdr[symtabindex].sh_size;
- ef->symbase = malloc(symcnt, M_LINKER, M_WAITOK);
- strcnt = shdr[symstrindex].sh_size;
- ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
+ symcnt = shdr[symtabindex].sh_size;
+ ef->symbase = malloc(symcnt, M_LINKER, M_WAITOK);
+ strcnt = shdr[symstrindex].sh_size;
+ ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
- if (ef->symbase == NULL || ef->strbase == NULL) {
- error = ENOMEM;
- goto out;
- }
- error = vn_rdwr(UIO_READ, nd.ni_vp,
- ef->symbase, symcnt, shdr[symtabindex].sh_offset,
- UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
- &resid, td);
- if (error)
- goto out;
- error = vn_rdwr(UIO_READ, nd.ni_vp,
- ef->strbase, strcnt, shdr[symstrindex].sh_offset,
- UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
- &resid, td);
- if (error)
- goto out;
+ if (ef->symbase == NULL || ef->strbase == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+ error = vn_rdwr(UIO_READ, nd.ni_vp,
+ ef->symbase, symcnt, shdr[symtabindex].sh_offset,
+ UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+ &resid, td);
+ if (error != 0)
+ goto out;
+ error = vn_rdwr(UIO_READ, nd.ni_vp,
+ ef->strbase, strcnt, shdr[symstrindex].sh_offset,
+ UIO_SYSSPACE, IO_NODELOCKED, td->td_ucred, NOCRED,
+ &resid, td);
+ if (error != 0)
+ goto out;
- ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
- ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
- ef->ddbstrcnt = strcnt;
- ef->ddbstrtab = ef->strbase;
+ ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
+ ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
+ ef->ddbstrcnt = strcnt;
+ ef->ddbstrtab = ef->strbase;
- error = link_elf_link_common_finish(lf);
- if (error)
- goto out;
+ error = link_elf_link_common_finish(lf);
+ if (error != 0)
+ goto out;
nosyms:
-
- *result = lf;
+ *result = lf;
out:
- VOP_UNLOCK(nd.ni_vp, 0);
- vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
- VFS_UNLOCK_GIANT(vfslocked);
- if (error && lf)
- linker_file_unload(lf, LINKER_UNLOAD_FORCE);
- if (shdr)
- free(shdr, M_LINKER);
- if (firstpage)
- free(firstpage, M_LINKER);
-
- return error;
+ VOP_UNLOCK(nd.ni_vp, 0);
+ vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
+ VFS_UNLOCK_GIANT(vfslocked);
+ if (error != 0 && lf != NULL)
+ linker_file_unload(lf, LINKER_UNLOAD_FORCE);
+ if (shdr != NULL)
+ free(shdr, M_LINKER);
+ if (firstpage != NULL)
+ free(firstpage, M_LINKER);
+
+ return (error);
}
Elf_Addr
elf_relocaddr(linker_file_t lf, Elf_Addr x)
{
- elf_file_t ef;
+ elf_file_t ef;
- ef = (elf_file_t)lf;
- if (x >= ef->pcpu_start && x < ef->pcpu_stop)
- return ((x - ef->pcpu_start) + ef->pcpu_base);
+ ef = (elf_file_t)lf;
+ if (x >= ef->pcpu_start && x < ef->pcpu_stop)
+ return ((x - ef->pcpu_start) + ef->pcpu_base);
#ifdef VIMAGE
- if (x >= ef->vnet_start && x < ef->vnet_stop)
- return ((x - ef->vnet_start) + ef->vnet_base);
+ if (x >= ef->vnet_start && x < ef->vnet_stop)
+ return ((x - ef->vnet_start) + ef->vnet_base);
#endif
- return (x);
+ return (x);
}
static void
link_elf_unload_file(linker_file_t file)
{
- elf_file_t ef = (elf_file_t) file;
+ elf_file_t ef = (elf_file_t) file;
- if (ef->pcpu_base) {
- dpcpu_free((void *)ef->pcpu_base, ef->pcpu_stop - ef->pcpu_start);
- }
+ if (ef->pcpu_base != 0) {
+ dpcpu_free((void *)ef->pcpu_base,
+ ef->pcpu_stop - ef->pcpu_start);
+ }
#ifdef VIMAGE
- if (ef->vnet_base) {
- vnet_data_free((void *)ef->vnet_base, ef->vnet_stop - ef->vnet_start);
- }
+ if (ef->vnet_base != 0) {
+ vnet_data_free((void *)ef->vnet_base,
+ ef->vnet_stop - ef->vnet_start);
+ }
#endif
#ifdef GDB
- if (ef->gdb.l_ld) {
- GDB_STATE(RT_DELETE);
- free((void *)(uintptr_t)ef->gdb.l_name, M_LINKER);
- link_elf_delete_gdb(&ef->gdb);
- GDB_STATE(RT_CONSISTENT);
- }
+ if (ef->gdb.l_ld != NULL) {
+ GDB_STATE(RT_DELETE);
+ free((void *)(uintptr_t)ef->gdb.l_name, M_LINKER);
+ link_elf_delete_gdb(&ef->gdb);
+ GDB_STATE(RT_CONSISTENT);
+ }
#endif
- /* Notify MD code that a module is being unloaded. */
- elf_cpu_unload_file(file);
+ /* Notify MD code that a module is being unloaded. */
+ elf_cpu_unload_file(file);
- if (ef->preloaded) {
- link_elf_unload_preload(file);
- return;
- }
+ if (ef->preloaded) {
+ link_elf_unload_preload(file);
+ return;
+ }
#ifdef SPARSE_MAPPING
- if (ef->object) {
- vm_map_remove(kernel_map, (vm_offset_t) ef->address,
- (vm_offset_t) ef->address
- + (ef->object->size << PAGE_SHIFT));
- }
+ if (ef->object != NULL) {
+ vm_map_remove(kernel_map, (vm_offset_t) ef->address,
+ (vm_offset_t) ef->address
+ + (ef->object->size << PAGE_SHIFT));
+ }
#else
- if (ef->address)
- free(ef->address, M_LINKER);
+ if (ef->address != NULL)
+ free(ef->address, M_LINKER);
#endif
- if (ef->symbase)
- free(ef->symbase, M_LINKER);
- if (ef->strbase)
- free(ef->strbase, M_LINKER);
- if (ef->ctftab)
- free(ef->ctftab, M_LINKER);
- if (ef->ctfoff)
- free(ef->ctfoff, M_LINKER);
- if (ef->typoff)
- free(ef->typoff, M_LINKER);
+ if (ef->symbase != NULL)
+ free(ef->symbase, M_LINKER);
+ if (ef->strbase != NULL)
+ free(ef->strbase, M_LINKER);
+ if (ef->ctftab != NULL)
+ free(ef->ctftab, M_LINKER);
+ if (ef->ctfoff != NULL)
+ free(ef->ctfoff, M_LINKER);
+ if (ef->typoff != NULL)
+ free(ef->typoff, M_LINKER);
}
static void
link_elf_unload_preload(linker_file_t file)
{
- if (file->filename)
- preload_delete_name(file->filename);
+ if (file->filename != NULL)
+ preload_delete_name(file->filename);
}
static const char *
symbol_name(elf_file_t ef, Elf_Size r_info)
{
- const Elf_Sym *ref;
+ const Elf_Sym *ref;
- if (ELF_R_SYM(r_info)) {
- ref = ef->symtab + ELF_R_SYM(r_info);
- return ef->strtab + ref->st_name;
- } else
- return NULL;
+ if (ELF_R_SYM(r_info)) {
+ ref = ef->symtab + ELF_R_SYM(r_info);
+ return (ef->strtab + ref->st_name);
+ }
+ return (NULL);
}
static int
relocate_file(elf_file_t ef)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
- const Elf_Rela *relalim;
- const Elf_Rela *rela;
- const char *symname;
-
- /* Perform relocations without addend if there are any: */
- rel = ef->rel;
- if (rel) {
- rellim = (const Elf_Rel *)((const char *)ef->rel + ef->relsize);
- while (rel < rellim) {
- if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
- elf_lookup)) {
- symname = symbol_name(ef, rel->r_info);
- printf("link_elf: symbol %s undefined\n", symname);
- return ENOENT;
- }
- rel++;
+ const Elf_Rel *rellim;
+ const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
+ const char *symname;
+
+ /* Perform relocations without addend if there are any: */
+ rel = ef->rel;
+ if (rel != NULL) {
+ rellim = (const Elf_Rel *)
+ ((const char *)ef->rel + ef->relsize);
+ while (rel < rellim) {
+ if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel,
+ ELF_RELOC_REL, elf_lookup)) {
+ symname = symbol_name(ef, rel->r_info);
+ printf("link_elf: symbol %s undefined\n", symname);
+ return (ENOENT);
+ }
+ rel++;
+ }
}
- }
- /* Perform relocations with addend if there are any: */
- rela = ef->rela;
- if (rela) {
- relalim = (const Elf_Rela *)((const char *)ef->rela + ef->relasize);
- while (rela < relalim) {
- if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
- elf_lookup)) {
- symname = symbol_name(ef, rela->r_info);
- printf("link_elf: symbol %s undefined\n", symname);
- return ENOENT;
- }
- rela++;
+ /* Perform relocations with addend if there are any: */
+ rela = ef->rela;
+ if (rela != NULL) {
+ relalim = (const Elf_Rela *)
+ ((const char *)ef->rela + ef->relasize);
+ while (rela < relalim) {
+ if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela,
+ ELF_RELOC_RELA, elf_lookup)) {
+ symname = symbol_name(ef, rela->r_info);
+ printf("link_elf: symbol %s undefined\n",
+ symname);
+ return (ENOENT);
+ }
+ rela++;
+ }
}
- }
- /* Perform PLT relocations without addend if there are any: */
- rel = ef->pltrel;
- if (rel) {
- rellim = (const Elf_Rel *)((const char *)ef->pltrel + ef->pltrelsize);
- while (rel < rellim) {
- if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
- elf_lookup)) {
- symname = symbol_name(ef, rel->r_info);
- printf("link_elf: symbol %s undefined\n", symname);
- return ENOENT;
- }
- rel++;
+ /* Perform PLT relocations without addend if there are any: */
+ rel = ef->pltrel;
+ if (rel != NULL) {
+ rellim = (const Elf_Rel *)
+ ((const char *)ef->pltrel + ef->pltrelsize);
+ while (rel < rellim) {
+ if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rel,
+ ELF_RELOC_REL, elf_lookup)) {
+ symname = symbol_name(ef, rel->r_info);
+ printf("link_elf: symbol %s undefined\n",
+ symname);
+ return (ENOENT);
+ }
+ rel++;
+ }
}
- }
- /* Perform relocations with addend if there are any: */
- rela = ef->pltrela;
- if (rela) {
- relalim = (const Elf_Rela *)((const char *)ef->pltrela + ef->pltrelasize);
- while (rela < relalim) {
- if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
- elf_lookup)) {
- symname = symbol_name(ef, rela->r_info);
- printf("link_elf: symbol %s undefined\n", symname);
- return ENOENT;
- }
- rela++;
+ /* Perform relocations with addend if there are any: */
+ rela = ef->pltrela;
+ if (rela != NULL) {
+ relalim = (const Elf_Rela *)
+ ((const char *)ef->pltrela + ef->pltrelasize);
+ while (rela < relalim) {
+ if (elf_reloc(&ef->lf, (Elf_Addr)ef->address, rela,
+ ELF_RELOC_RELA, elf_lookup)) {
+ symname = symbol_name(ef, rela->r_info);
+ printf("link_elf: symbol %s undefined\n",
+ symname);
+ return (ENOENT);
+ }
+ rela++;
+ }
}
- }
- return 0;
+ return (0);
}
/*
@@ -1146,113 +1162,114 @@ relocate_file(elf_file_t ef)
static unsigned long
elf_hash(const char *name)
{
- const unsigned char *p = (const unsigned char *) name;
- unsigned long h = 0;
- unsigned long g;
-
- while (*p != '\0') {
- h = (h << 4) + *p++;
- if ((g = h & 0xf0000000) != 0)
- h ^= g >> 24;
- h &= ~g;
- }
- return h;
+ const unsigned char *p = (const unsigned char *) name;
+ unsigned long h = 0;
+ unsigned long g;
+
+ while (*p != '\0') {
+ h = (h << 4) + *p++;
+ if ((g = h & 0xf0000000) != 0)
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return (h);
}
static int
link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
{
- elf_file_t ef = (elf_file_t) lf;
- unsigned long symnum;
- const Elf_Sym* symp;
- const char *strp;
- unsigned long hash;
- int i;
-
- /* If we don't have a hash, bail. */
- if (ef->buckets == NULL || ef->nbuckets == 0) {
- printf("link_elf_lookup_symbol: missing symbol hash table\n");
- return ENOENT;
- }
-
- /* First, search hashed global symbols */
- hash = elf_hash(name);
- symnum = ef->buckets[hash % ef->nbuckets];
+ elf_file_t ef = (elf_file_t) lf;
+ unsigned long symnum;
+ const Elf_Sym* symp;
+ const char *strp;
+ unsigned long hash;
+ int i;
- while (symnum != STN_UNDEF) {
- if (symnum >= ef->nchains) {
- printf("link_elf_lookup_symbol: corrupt symbol table\n");
- return ENOENT;
+ /* If we don't have a hash, bail. */
+ if (ef->buckets == NULL || ef->nbuckets == 0) {
+ printf("link_elf_lookup_symbol: missing symbol hash table\n");
+ return (ENOENT);
}
- symp = ef->symtab + symnum;
- if (symp->st_name == 0) {
- printf("link_elf_lookup_symbol: corrupt symbol table\n");
- return ENOENT;
- }
+ /* First, search hashed global symbols */
+ hash = elf_hash(name);
+ symnum = ef->buckets[hash % ef->nbuckets];
+
+ while (symnum != STN_UNDEF) {
+ if (symnum >= ef->nchains) {
+ printf("%s: corrupt symbol table\n", __func__);
+ return (ENOENT);
+ }
- strp = ef->strtab + symp->st_name;
+ symp = ef->symtab + symnum;
+ if (symp->st_name == 0) {
+ printf("%s: corrupt symbol table\n", __func__);
+ return (ENOENT);
+ }
+
+ strp = ef->strtab + symp->st_name;
- if (strcmp(name, strp) == 0) {
- if (symp->st_shndx != SHN_UNDEF ||
- (symp->st_value != 0 &&
- ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
- *sym = (c_linker_sym_t) symp;
- return 0;
- } else
- return ENOENT;
+ if (strcmp(name, strp) == 0) {
+ if (symp->st_shndx != SHN_UNDEF ||
+ (symp->st_value != 0 &&
+ ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
+ *sym = (c_linker_sym_t) symp;
+ return (0);
+ }
+ return (ENOENT);
+ }
+
+ symnum = ef->chains[symnum];
}
- symnum = ef->chains[symnum];
- }
+ /* If we have not found it, look at the full table (if loaded) */
+ if (ef->symtab == ef->ddbsymtab)
+ return (ENOENT);
- /* If we have not found it, look at the full table (if loaded) */
- if (ef->symtab == ef->ddbsymtab)
- return ENOENT;
-
- /* Exhaustive search */
- for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
- strp = ef->ddbstrtab + symp->st_name;
- if (strcmp(name, strp) == 0) {
- if (symp->st_shndx != SHN_UNDEF ||
- (symp->st_value != 0 &&
- ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
- *sym = (c_linker_sym_t) symp;
- return 0;
- } else
- return ENOENT;
+ /* Exhaustive search */
+ for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
+ strp = ef->ddbstrtab + symp->st_name;
+ if (strcmp(name, strp) == 0) {
+ if (symp->st_shndx != SHN_UNDEF ||
+ (symp->st_value != 0 &&
+ ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
+ *sym = (c_linker_sym_t) symp;
+ return (0);
+ }
+ return (ENOENT);
+ }
}
- }
- return ENOENT;
+ return (ENOENT);
}
static int
-link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t* symval)
+link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym,
+ linker_symval_t *symval)
{
elf_file_t ef = (elf_file_t) lf;
const Elf_Sym* es = (const Elf_Sym*) sym;
if (es >= ef->symtab && es < (ef->symtab + ef->nchains)) {
- symval->name = ef->strtab + es->st_name;
- symval->value = (caddr_t) ef->address + es->st_value;
- symval->size = es->st_size;
- return 0;
+ symval->name = ef->strtab + es->st_name;
+ symval->value = (caddr_t) ef->address + es->st_value;
+ symval->size = es->st_size;
+ return (0);
}
if (ef->symtab == ef->ddbsymtab)
- return ENOENT;
+ return (ENOENT);
if (es >= ef->ddbsymtab && es < (ef->ddbsymtab + ef->ddbsymcnt)) {
- symval->name = ef->ddbstrtab + es->st_name;
- symval->value = (caddr_t) ef->address + es->st_value;
- symval->size = es->st_size;
- return 0;
+ symval->name = ef->ddbstrtab + es->st_name;
+ symval->value = (caddr_t) ef->address + es->st_value;
+ symval->size = es->st_size;
+ return (0);
}
- return ENOENT;
+ return (ENOENT);
}
static int
link_elf_search_symbol(linker_file_t lf, caddr_t value,
- c_linker_sym_t* sym, long* diffp)
+ c_linker_sym_t *sym, long *diffp)
{
elf_file_t ef = (elf_file_t) lf;
u_long off = (uintptr_t) (void *) value;
@@ -1283,7 +1300,7 @@ link_elf_search_symbol(linker_file_t lf, caddr_t value,
*diffp = diff;
*sym = (c_linker_sym_t) best;
- return 0;
+ return (0);
}
/*
@@ -1291,7 +1308,7 @@ link_elf_search_symbol(linker_file_t lf, caddr_t value,
*/
static int
link_elf_lookup_set(linker_file_t lf, const char *name,
- void ***startp, void ***stopp, int *countp)
+ void ***startp, void ***stopp, int *countp)
{
c_linker_sym_t sym;
linker_symval_t symval;
@@ -1302,12 +1319,12 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
len = strlen(name) + sizeof("__start_set_"); /* sizeof includes \0 */
setsym = malloc(len, M_LINKER, M_WAITOK);
if (setsym == NULL)
- return ENOMEM;
+ return (ENOMEM);
/* get address of first entry */
snprintf(setsym, len, "%s%s", "__start_set_", name);
error = link_elf_lookup_symbol(lf, setsym, &sym);
- if (error)
+ if (error != 0)
goto out;
link_elf_symbol_values(lf, sym, &symval);
if (symval.value == 0) {
@@ -1319,7 +1336,7 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
/* get address of last entry */
snprintf(setsym, len, "%s%s", "__stop_set_", name);
error = link_elf_lookup_symbol(lf, setsym, &sym);
- if (error)
+ if (error != 0)
goto out;
link_elf_symbol_values(lf, sym, &symval);
if (symval.value == 0) {
@@ -1332,35 +1349,36 @@ link_elf_lookup_set(linker_file_t lf, const char *name,
count = stop - start;
/* and copy out */
- if (startp)
+ if (startp != NULL)
*startp = start;
- if (stopp)
+ if (stopp != NULL)
*stopp = stop;
- if (countp)
+ if (countp != NULL)
*countp = count;
out:
free(setsym, M_LINKER);
- return error;
+ return (error);
}
static int
link_elf_each_function_name(linker_file_t file,
- int (*callback)(const char *, void *), void *opaque) {
- elf_file_t ef = (elf_file_t)file;
- const Elf_Sym* symp;
- int i, error;
+ int (*callback)(const char *, void *), void *opaque)
+{
+ elf_file_t ef = (elf_file_t)file;
+ const Elf_Sym *symp;
+ int i, error;
- /* Exhaustive search */
- for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
- if (symp->st_value != 0 &&
- ELF_ST_TYPE(symp->st_info) == STT_FUNC) {
- error = callback(ef->ddbstrtab + symp->st_name, opaque);
- if (error)
- return (error);
+ /* Exhaustive search */
+ for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
+ if (symp->st_value != 0 &&
+ ELF_ST_TYPE(symp->st_info) == STT_FUNC) {
+ error = callback(ef->ddbstrtab + symp->st_name, opaque);
+ if (error != 0)
+ return (error);
+ }
}
- }
- return (0);
+ return (0);
}
static int
@@ -1376,11 +1394,12 @@ link_elf_each_function_nameval(linker_file_t file,
for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
if (symp->st_value != 0 &&
ELF_ST_TYPE(symp->st_info) == STT_FUNC) {
- error = link_elf_symbol_values(file, (c_linker_sym_t) symp, &symval);
- if (error)
+ error = link_elf_symbol_values(file,
+ (c_linker_sym_t) symp, &symval);
+ if (error != 0)
return (error);
error = callback(file, i, &symval, opaque);
- if (error)
+ if (error != 0)
return (error);
}
}
@@ -1398,7 +1417,7 @@ Elf_Addr
link_elf_get_gp(linker_file_t lf)
{
elf_file_t ef = (elf_file_t)lf;
- return (Elf_Addr)ef->got;
+ return ((Elf_Addr)ef->got);
}
#endif
@@ -1474,55 +1493,56 @@ elf_lookup(linker_file_t lf, Elf_Size symidx, int deps)
static void
link_elf_reloc_local(linker_file_t lf)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
- const Elf_Rela *relalim;
- const Elf_Rela *rela;
- elf_file_t ef = (elf_file_t)lf;
-
- /* Perform relocations without addend if there are any: */
- if ((rel = ef->rel) != NULL) {
- rellim = (const Elf_Rel *)((const char *)ef->rel + ef->relsize);
- while (rel < rellim) {
- elf_reloc_local(lf, (Elf_Addr)ef->address, rel, ELF_RELOC_REL,
- elf_lookup);
- rel++;
+ const Elf_Rel *rellim;
+ const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
+ elf_file_t ef = (elf_file_t)lf;
+
+ /* Perform relocations without addend if there are any: */
+ if ((rel = ef->rel) != NULL) {
+ rellim = (const Elf_Rel *)((const char *)ef->rel + ef->relsize);
+ while (rel < rellim) {
+ elf_reloc_local(lf, (Elf_Addr)ef->address, rel,
+ ELF_RELOC_REL, elf_lookup);
+ rel++;
+ }
}
- }
- /* Perform relocations with addend if there are any: */
- if ((rela = ef->rela) != NULL) {
- relalim = (const Elf_Rela *)((const char *)ef->rela + ef->relasize);
- while (rela < relalim) {
- elf_reloc_local(lf, (Elf_Addr)ef->address, rela, ELF_RELOC_RELA,
- elf_lookup);
- rela++;
+ /* Perform relocations with addend if there are any: */
+ if ((rela = ef->rela) != NULL) {
+ relalim = (const Elf_Rela *)
+ ((const char *)ef->rela + ef->relasize);
+ while (rela < relalim) {
+ elf_reloc_local(lf, (Elf_Addr)ef->address, rela,
+ ELF_RELOC_RELA, elf_lookup);
+ rela++;
+ }
}
- }
}
static long
link_elf_symtab_get(linker_file_t lf, const Elf_Sym **symtab)
{
- elf_file_t ef = (elf_file_t)lf;
-
- *symtab = ef->ddbsymtab;
-
- if (*symtab == NULL)
- return (0);
+ elf_file_t ef = (elf_file_t)lf;
- return (ef->ddbsymcnt);
+ *symtab = ef->ddbsymtab;
+
+ if (*symtab == NULL)
+ return (0);
+
+ return (ef->ddbsymcnt);
}
static long
link_elf_strtab_get(linker_file_t lf, caddr_t *strtab)
{
- elf_file_t ef = (elf_file_t)lf;
+ elf_file_t ef = (elf_file_t)lf;
- *strtab = ef->ddbstrtab;
+ *strtab = ef->ddbstrtab;
- if (*strtab == NULL)
- return (0);
+ if (*strtab == NULL)
+ return (0);
- return (ef->ddbstrcnt);
+ return (ef->ddbstrcnt);
}
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 0005968..d96c5a0 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -165,7 +165,7 @@ static struct td_sched td_sched0;
* before throttling back.
* SLP_RUN_FORK: Maximum slp+run time to inherit at fork time.
* INTERACT_MAX: Maximum interactivity value. Smaller is better.
- * INTERACT_THRESH: Threshhold for placement on the current runq.
+ * INTERACT_THRESH: Threshold for placement on the current runq.
*/
#define SCHED_SLP_RUN_MAX ((hz * 5) << SCHED_TICK_SHIFT)
#define SCHED_SLP_RUN_FORK ((hz / 2) << SCHED_TICK_SHIFT)
@@ -2179,7 +2179,7 @@ sched_tick(int cnt)
ts->ts_ltick = ticks;
ts->ts_incrtick = ticks;
/*
- * Update if we've exceeded our desired tick threshhold by over one
+ * Update if we've exceeded our desired tick threshold by over one
* second.
*/
if (ts->ts_ftick + SCHED_TICK_MAX < ts->ts_ltick)
diff --git a/sys/kern/subr_lock.c b/sys/kern/subr_lock.c
index 530ebc5..7d82126 100644
--- a/sys/kern/subr_lock.c
+++ b/sys/kern/subr_lock.c
@@ -170,7 +170,7 @@ SLIST_HEAD(lphead, lock_prof);
/*
* Array of objects and profs for each type of object for each cpu. Spinlocks
- * are handled seperately because a thread may be preempted and acquire a
+ * are handled separately because a thread may be preempted and acquire a
* spinlock while in the lock profiling code of a non-spinlock. In this way
* we only need a critical section to protect the per-cpu lists.
*/
diff --git a/sys/kern/subr_taskqueue.c b/sys/kern/subr_taskqueue.c
index fd6dd4f..49ddce2 100644
--- a/sys/kern/subr_taskqueue.c
+++ b/sys/kern/subr_taskqueue.c
@@ -68,23 +68,21 @@ struct taskqueue {
#define TQ_FLAGS_BLOCKED (1 << 1)
#define TQ_FLAGS_PENDING (1 << 2)
-static __inline void
-TQ_LOCK(struct taskqueue *tq)
-{
- if (tq->tq_spin)
- mtx_lock_spin(&tq->tq_mutex);
- else
- mtx_lock(&tq->tq_mutex);
-}
-
-static __inline void
-TQ_UNLOCK(struct taskqueue *tq)
-{
- if (tq->tq_spin)
- mtx_unlock_spin(&tq->tq_mutex);
- else
- mtx_unlock(&tq->tq_mutex);
-}
+#define TQ_LOCK(tq) \
+ do { \
+ if ((tq)->tq_spin) \
+ mtx_lock_spin(&(tq)->tq_mutex); \
+ else \
+ mtx_lock(&(tq)->tq_mutex); \
+ } while (0)
+
+#define TQ_UNLOCK(tq) \
+ do { \
+ if ((tq)->tq_spin) \
+ mtx_unlock_spin(&(tq)->tq_mutex); \
+ else \
+ mtx_unlock(&(tq)->tq_mutex); \
+ } while (0)
static __inline int
TQ_SLEEP(struct taskqueue *tq, void *p, struct mtx *m, int pri, const char *wm,
@@ -275,6 +273,24 @@ task_is_running(struct taskqueue *queue, struct task *task)
return (0);
}
+int
+taskqueue_cancel(struct taskqueue *queue, struct task *task, u_int *pendp)
+{
+ u_int pending;
+ int error;
+
+ TQ_LOCK(queue);
+ if ((pending = task->ta_pending) > 0)
+ STAILQ_REMOVE(&queue->tq_queue, task, task, ta_link);
+ task->ta_pending = 0;
+ error = task_is_running(queue, task) ? EBUSY : 0;
+ TQ_UNLOCK(queue);
+
+ if (pendp != NULL)
+ *pendp = pending;
+ return (error);
+}
+
void
taskqueue_drain(struct taskqueue *queue, struct task *task)
{
diff --git a/sys/mips/conf/SWARM b/sys/mips/conf/SWARM
index d4950cb..6db2181 100644
--- a/sys/mips/conf/SWARM
+++ b/sys/mips/conf/SWARM
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-include SWARM_COMMON
+include std.SWARM
ident SWARM
diff --git a/sys/mips/conf/SWARM64 b/sys/mips/conf/SWARM64
index 72931b5..af04269 100644
--- a/sys/mips/conf/SWARM64
+++ b/sys/mips/conf/SWARM64
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-include SWARM_COMMON
+include std.SWARM
ident SWARM64
diff --git a/sys/mips/conf/SWARM64_SMP b/sys/mips/conf/SWARM64_SMP
index 863c0f0..7985210 100644
--- a/sys/mips/conf/SWARM64_SMP
+++ b/sys/mips/conf/SWARM64_SMP
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-include SWARM_COMMON
+include std.SWARM
ident SWARM64_SMP
diff --git a/sys/mips/conf/SWARM_COMMON b/sys/mips/conf/SWARM_COMMON
deleted file mode 100644
index 1d22e3c..0000000
--- a/sys/mips/conf/SWARM_COMMON
+++ /dev/null
@@ -1,60 +0,0 @@
-#
-# $FreeBSD$
-#
-
-files "../sibyte/files.sibyte"
-hints "SWARM.hints"
-
-options CFE
-options CFE_CONSOLE
-options CFE_ENV
-options ALT_BREAK_TO_DEBUGGER
-
-cpu CPU_SB1
-
-makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols
-makeoptions MODULES_OVERRIDE=""
-
-options DDB
-options KDB
-
-options SCHED_4BSD #4BSD scheduler
-options INET #InterNETworking
-options NFSCLIENT #Network Filesystem Client
-options NFS_ROOT #NFS usable as /, requires NFSCLIENT
-options PSEUDOFS #Pseudo-filesystem framework
-options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions
-
-# Debugging for use in -current
-#options DEADLKRES
-options INVARIANTS
-options INVARIANT_SUPPORT
-options WITNESS
-
-options FFS #Fast filesystem
-
-options KTRACE
-
-device pci
-device miibus
-device bge
-device loop
-device ether
-device md
-device random
-
-options USB_DEBUG
-device usb
-device ohci
-device uhci
-device ehci
-
-device umass
-
-device scbus
-device da
-
-device ata
-device atadisk
-device atapicd
-options ATA_STATIC_ID
diff --git a/sys/mips/conf/SWARM_SMP b/sys/mips/conf/SWARM_SMP
index 534d085..925f1bb 100644
--- a/sys/mips/conf/SWARM_SMP
+++ b/sys/mips/conf/SWARM_SMP
@@ -2,7 +2,7 @@
# $FreeBSD$
#
-include SWARM_COMMON
+include std.SWARM
ident SWARM_SMP
diff --git a/sys/mips/conf/XLR b/sys/mips/conf/XLR
index 9d640d2..34551d8 100644
--- a/sys/mips/conf/XLR
+++ b/sys/mips/conf/XLR
@@ -77,7 +77,7 @@ options NFS_ROOT
options BOOTP
options BOOTP_NFSROOT
options BOOTP_NFSV3
-options BOOTP_WIRED_TO=rge0
+options BOOTP_WIRED_TO=nlge0
options BOOTP_COMPAT
options ROOTDEVNAME=\"nfs:10.1.1.8:/usr/extra/nfsroot\"
#
@@ -123,7 +123,7 @@ device bpf
# Network
device miibus
-device rge
+device nlge
device ether
device re
device msk
diff --git a/sys/mips/conf/XLR64 b/sys/mips/conf/XLR64
index 949f9bd..4bc8794 100644
--- a/sys/mips/conf/XLR64
+++ b/sys/mips/conf/XLR64
@@ -50,7 +50,7 @@ options NFS_ROOT
options BOOTP
options BOOTP_NFSROOT
options BOOTP_NFSV3
-options BOOTP_WIRED_TO=rge0
+options BOOTP_WIRED_TO=nlge0
options BOOTP_COMPAT
options ROOTDEVNAME=\"nfs:10.1.1.8:/usr/extra/nfsroot\"
#
@@ -96,7 +96,7 @@ device bpf
# Network
device miibus
-device rge
+device nlge
device ether
device re
device msk
diff --git a/sys/mips/conf/XLRN32 b/sys/mips/conf/XLRN32
index 1e0c8f3..d26a1a4 100644
--- a/sys/mips/conf/XLRN32
+++ b/sys/mips/conf/XLRN32
@@ -50,7 +50,7 @@ options NFS_ROOT
options BOOTP
options BOOTP_NFSROOT
options BOOTP_NFSV3
-options BOOTP_WIRED_TO=rge0
+options BOOTP_WIRED_TO=nlge0
options BOOTP_COMPAT
options ROOTDEVNAME=\"nfs:10.1.1.8:/usr/extra/nfsroot\"
#
@@ -96,7 +96,7 @@ device bpf
# Network
device miibus
-device rge
+device nlge
device ether
device re
device msk
diff --git a/sys/mips/include/cpuregs.h b/sys/mips/include/cpuregs.h
index bc55a7e..456c545 100644
--- a/sys/mips/include/cpuregs.h
+++ b/sys/mips/include/cpuregs.h
@@ -181,6 +181,9 @@
#define MIPS_XUSEG_END 0x0000010000000000
#define MIPS_XKSEG_START 0xc000000000000000
#define MIPS_XKSEG_END 0xc00000ff80000000
+#define MIPS_XKSEG_COMPAT32_START 0xffffffff80000000
+#define MIPS_XKSEG_COMPAT32_END 0xffffffffffffffff
+#define MIPS_XKSEG_TO_COMPAT32(va) ((va) & 0xffffffff)
#ifdef __mips_n64
#define MIPS_DIRECT_MAPPABLE(pa) 1
diff --git a/sys/mips/include/md_var.h b/sys/mips/include/md_var.h
index fee2e44..3cebbdc 100644
--- a/sys/mips/include/md_var.h
+++ b/sys/mips/include/md_var.h
@@ -42,6 +42,8 @@
extern long Maxmem;
extern char sigcode[];
extern int szsigcode, szosigcode;
+extern uint32_t *vm_page_dump;
+extern int vm_page_dump_size;
extern vm_offset_t kstack0;
extern vm_offset_t kernel_kseg0_end;
@@ -74,4 +76,7 @@ void platform_identify(void);
extern int busdma_swi_pending;
void busdma_swi(void);
+
+struct dumperinfo;
+void minidumpsys(struct dumperinfo *);
#endif /* !_MACHINE_MD_VAR_H_ */
diff --git a/sys/mips/include/mutex.h b/sys/mips/include/mutex.h
deleted file mode 100644
index cbc066d..0000000
--- a/sys/mips/include/mutex.h
+++ /dev/null
@@ -1,2 +0,0 @@
-/* $FreeBSD$ */
-/* Empty file */
diff --git a/sys/mips/include/pmap.h b/sys/mips/include/pmap.h
index 558a018..c082abb 100644
--- a/sys/mips/include/pmap.h
+++ b/sys/mips/include/pmap.h
@@ -144,6 +144,8 @@ extern vm_offset_t physmem_desc[PHYS_AVAIL_ENTRIES + 2];
extern vm_offset_t virtual_avail;
extern vm_offset_t virtual_end;
+extern vm_paddr_t dump_avail[PHYS_AVAIL_ENTRIES + 2];
+
#define pmap_page_get_memattr(m) VM_MEMATTR_DEFAULT
#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list))
#define pmap_page_set_memattr(m, ma) (void)0
diff --git a/sys/mips/mips/dump_machdep.c b/sys/mips/mips/dump_machdep.c
index 3700689..78938de 100644
--- a/sys/mips/mips/dump_machdep.c
+++ b/sys/mips/mips/dump_machdep.c
@@ -1,35 +1,362 @@
/*-
- * Copyright (c) 2006 Oleksandr Tymoshenko
+ * Copyright (c) 2002 Marcel Moolenaar
* 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,
- * without modification, immediately at the beginning of the file.
- * 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 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.
+ * 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 ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/* Note to writer, when using pmap_kenter_temporary() you must,
- * after using the va to write out the page, call
- * pmap_kenter_temporary_free(). You should probably also
- * pin the dump thread to the CPU with sched_pin().
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/cons.h>
+#include <sys/sysctl.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/kerneldump.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <machine/elf.h>
+#include <machine/md_var.h>
+#include <machine/pcb.h>
+#include <machine/cache.h>
+
+CTASSERT(sizeof(struct kerneldumpheader) == 512);
+
+int do_minidump = 1;
+TUNABLE_INT("debug.minidump", &do_minidump);
+SYSCTL_INT(_debug, OID_AUTO, minidump, CTLFLAG_RW, &do_minidump, 0,
+ "Enable mini crash dumps");
+
+/*
+ * Don't touch the first SIZEOF_METADATA bytes on the dump device. This
+ * is to protect us from metadata and to protect metadata from us.
*/
+#define SIZEOF_METADATA (64*1024)
+
+#define MD_ALIGN(x) (((off_t)(x) + PAGE_MASK) & ~PAGE_MASK)
+#define DEV_ALIGN(x) (((off_t)(x) + (DEV_BSIZE-1)) & ~(DEV_BSIZE-1))
+extern struct pcb dumppcb;
+
+struct md_pa {
+ vm_paddr_t md_start;
+ vm_paddr_t md_size;
+};
+
+typedef int callback_t(struct md_pa *, int, void *);
+
+static struct kerneldumpheader kdh;
+static off_t dumplo, fileofs;
+
+/* Handle buffered writes. */
+static char buffer[DEV_BSIZE];
+static size_t fragsz;
+
+/* XXX: I suppose 20 should be enough. */
+static struct md_pa dump_map[20];
+
+static void
+md_pa_init(void)
+{
+ int n, idx;
+
+ bzero(dump_map, sizeof(dump_map));
+ for (n = 0; n < sizeof(dump_map) / sizeof(dump_map[0]); n++) {
+ idx = n * 2;
+ if (dump_avail[idx] == 0 && dump_avail[idx + 1] == 0)
+ break;
+ dump_map[n].md_start = dump_avail[idx];
+ dump_map[n].md_size = dump_avail[idx + 1] - dump_avail[idx];
+ }
+}
+
+static struct md_pa *
+md_pa_first(void)
+{
+
+ return (&dump_map[0]);
+}
+
+static struct md_pa *
+md_pa_next(struct md_pa *mdp)
+{
+
+ mdp++;
+ if (mdp->md_size == 0)
+ mdp = NULL;
+ return (mdp);
+}
+
+static int
+buf_write(struct dumperinfo *di, char *ptr, size_t sz)
+{
+ size_t len;
+ int error;
+
+ while (sz) {
+ len = DEV_BSIZE - fragsz;
+ if (len > sz)
+ len = sz;
+ bcopy(ptr, buffer + fragsz, len);
+ fragsz += len;
+ ptr += len;
+ sz -= len;
+ if (fragsz == DEV_BSIZE) {
+ error = dump_write(di, buffer, 0, dumplo,
+ DEV_BSIZE);
+ if (error)
+ return error;
+ dumplo += DEV_BSIZE;
+ fragsz = 0;
+ }
+ }
+
+ return (0);
+}
+
+static int
+buf_flush(struct dumperinfo *di)
+{
+ int error;
+
+ if (fragsz == 0)
+ return (0);
+
+ error = dump_write(di, buffer, 0, dumplo, DEV_BSIZE);
+ dumplo += DEV_BSIZE;
+ fragsz = 0;
+ return (error);
+}
+
+extern vm_offset_t kernel_l1kva;
+extern char *pouet2;
+
+static int
+cb_dumpdata(struct md_pa *mdp, int seqnr, void *arg)
+{
+ struct dumperinfo *di = (struct dumperinfo*)arg;
+ vm_paddr_t pa;
+ uint32_t pgs;
+ size_t counter, sz, chunk;
+ int c, error;
+
+ error = 0; /* catch case in which chunk size is 0 */
+ counter = 0;
+ pgs = mdp->md_size / PAGE_SIZE;
+ pa = mdp->md_start;
+
+ printf(" chunk %d: %dMB (%d pages)", seqnr, pgs * PAGE_SIZE / (
+ 1024*1024), pgs);
+
+ /* Make sure we write coherent datas. */
+ mips_dcache_wbinv_all();
+ while (pgs) {
+ chunk = pgs;
+ if (chunk > MAXDUMPPGS)
+ chunk = MAXDUMPPGS;
+ sz = chunk << PAGE_SHIFT;
+ counter += sz;
+ if (counter >> 24) {
+ printf(" %d", pgs * PAGE_SIZE);
+ counter &= (1<<24) - 1;
+ }
+
+ error = dump_write(di, (void *)(pa),0, dumplo, sz);
+ if (error)
+ break;
+ dumplo += sz;
+ pgs -= chunk;
+ pa += sz;
+
+ /* Check for user abort. */
+ c = cncheckc();
+ if (c == 0x03)
+ return (ECANCELED);
+ if (c != -1)
+ printf(" (CTRL-C to abort) ");
+ }
+ printf(" ... %s\n", (error) ? "fail" : "ok");
+ return (error);
+}
+
+static int
+cb_dumphdr(struct md_pa *mdp, int seqnr, void *arg)
+{
+ struct dumperinfo *di = (struct dumperinfo*)arg;
+ Elf_Phdr phdr;
+ uint64_t size;
+ int error;
+
+ size = mdp->md_size;
+ bzero(&phdr, sizeof(phdr));
+ phdr.p_type = PT_LOAD;
+ phdr.p_flags = PF_R; /* XXX */
+ phdr.p_offset = fileofs;
+ phdr.p_vaddr = mdp->md_start;
+ phdr.p_paddr = mdp->md_start;
+ phdr.p_filesz = size;
+ phdr.p_memsz = size;
+ phdr.p_align = PAGE_SIZE;
+
+ error = buf_write(di, (char*)&phdr, sizeof(phdr));
+ fileofs += phdr.p_filesz;
+ return (error);
+}
+
+static int
+cb_size(struct md_pa *mdp, int seqnr, void *arg)
+{
+ uint32_t *sz = (uint32_t*)arg;
+
+ *sz += (uint32_t)mdp->md_size;
+ return (0);
+}
+
+static int
+foreach_chunk(callback_t cb, void *arg)
+{
+ struct md_pa *mdp;
+ int error, seqnr;
+
+ seqnr = 0;
+ mdp = md_pa_first();
+ while (mdp != NULL) {
+ error = (*cb)(mdp, seqnr++, arg);
+ if (error)
+ return (-error);
+ mdp = md_pa_next(mdp);
+ }
+ return (seqnr);
+}
+
+void
+dumpsys(struct dumperinfo *di)
+{
+ Elf_Ehdr ehdr;
+ uint32_t dumpsize;
+ off_t hdrgap;
+ size_t hdrsz;
+ int error;
+
+ if (do_minidump) {
+ minidumpsys(di);
+ return;
+ }
+
+ bzero(&ehdr, sizeof(ehdr));
+ ehdr.e_ident[EI_MAG0] = ELFMAG0;
+ ehdr.e_ident[EI_MAG1] = ELFMAG1;
+ ehdr.e_ident[EI_MAG2] = ELFMAG2;
+ ehdr.e_ident[EI_MAG3] = ELFMAG3;
+ ehdr.e_ident[EI_CLASS] = ELF_CLASS;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ ehdr.e_ident[EI_DATA] = ELFDATA2LSB;
+#else
+ ehdr.e_ident[EI_DATA] = ELFDATA2MSB;
+#endif
+ ehdr.e_ident[EI_VERSION] = EV_CURRENT;
+ ehdr.e_ident[EI_OSABI] = ELFOSABI_STANDALONE; /* XXX big picture? */
+ ehdr.e_type = ET_CORE;
+ ehdr.e_machine = EM_MIPS;
+ ehdr.e_phoff = sizeof(ehdr);
+ ehdr.e_flags = 0;
+ ehdr.e_ehsize = sizeof(ehdr);
+ ehdr.e_phentsize = sizeof(Elf_Phdr);
+ ehdr.e_shentsize = sizeof(Elf_Shdr);
+
+ md_pa_init();
+
+ /* Calculate dump size. */
+ dumpsize = 0L;
+ ehdr.e_phnum = foreach_chunk(cb_size, &dumpsize);
+ hdrsz = ehdr.e_phoff + ehdr.e_phnum * ehdr.e_phentsize;
+ fileofs = MD_ALIGN(hdrsz);
+ dumpsize += fileofs;
+ hdrgap = fileofs - DEV_ALIGN(hdrsz);
+
+ /* Determine dump offset on device. */
+ if (di->mediasize < SIZEOF_METADATA + dumpsize + sizeof(kdh) * 2) {
+ error = ENOSPC;
+ goto fail;
+ }
+ dumplo = di->mediaoffset + di->mediasize - dumpsize;
+ dumplo -= sizeof(kdh) * 2;
+
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION, dumpsize, di->blocksize);
+
+ printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20,
+ ehdr.e_phnum);
+
+ /* Dump leader */
+ error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
+ if (error)
+ goto fail;
+ dumplo += sizeof(kdh);
+
+ /* Dump ELF header */
+ error = buf_write(di, (char*)&ehdr, sizeof(ehdr));
+ if (error)
+ goto fail;
+
+ /* Dump program headers */
+ error = foreach_chunk(cb_dumphdr, di);
+ if (error < 0)
+ goto fail;
+ buf_flush(di);
+
+ /*
+ * All headers are written using blocked I/O, so we know the
+ * current offset is (still) block aligned. Skip the alignement
+ * in the file to have the segment contents aligned at page
+ * boundary. We cannot use MD_ALIGN on dumplo, because we don't
+ * care and may very well be unaligned within the dump device.
+ */
+ dumplo += hdrgap;
+
+ /* Dump memory chunks (updates dumplo) */
+ error = foreach_chunk(cb_dumpdata, di);
+ if (error < 0)
+ goto fail;
+
+ /* Dump trailer */
+ error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
+ if (error)
+ goto fail;
+
+ /* Signal completion, signoff and exit stage left. */
+ dump_write(di, NULL, 0, 0, 0);
+ printf("\nDump complete\n");
+ return;
+
+ fail:
+ if (error < 0)
+ error = -error;
+
+ if (error == ECANCELED)
+ printf("\nDump aborted\n");
+ else if (error == ENOSPC)
+ printf("\nDump failed. Partition too small.\n");
+ else
+ printf("\n** DUMP FAILED (ERROR %d) **\n", error);
+}
diff --git a/sys/mips/mips/gdb_machdep.c b/sys/mips/mips/gdb_machdep.c
index 0f5b5ed..780a4f1 100644
--- a/sys/mips/mips/gdb_machdep.c
+++ b/sys/mips/mips/gdb_machdep.c
@@ -117,26 +117,33 @@ gdb_cpu_getreg(int regnum, size_t *regsz)
*regsz = gdb_cpu_regsz(regnum);
if (kdb_thread == PCPU_GET(curthread)) {
- switch (regnum) {
- /*
- * XXX: May need to add more registers
- */
- case 2: return (&kdb_frame->v0);
- case 3: return (&kdb_frame->v1);
- }
+ register_t *zero_ptr = &kdb_frame->zero;
+ return zero_ptr + regnum;
}
+
switch (regnum) {
- case 16: return (&kdb_thrctx->pcb_context[0]);
- case 17: return (&kdb_thrctx->pcb_context[1]);
- case 18: return (&kdb_thrctx->pcb_context[2]);
- case 19: return (&kdb_thrctx->pcb_context[3]);
- case 20: return (&kdb_thrctx->pcb_context[4]);
- case 21: return (&kdb_thrctx->pcb_context[5]);
- case 22: return (&kdb_thrctx->pcb_context[6]);
- case 23: return (&kdb_thrctx->pcb_context[7]);
- case 29: return (&kdb_thrctx->pcb_context[8]);
- case 30: return (&kdb_thrctx->pcb_context[9]);
- case 31: return (&kdb_thrctx->pcb_context[10]);
+ /*
+ * S0..S7
+ */
+ case 16:
+ case 17:
+ case 18:
+ case 19:
+ case 20:
+ case 21:
+ case 22:
+ case 23:
+ return (&kdb_thrctx->pcb_context[PCB_REG_S0 + regnum - 16]);
+ case 28:
+ return (&kdb_thrctx->pcb_context[PCB_REG_GP]);
+ case 29:
+ return (&kdb_thrctx->pcb_context[PCB_REG_SP]);
+ case 30:
+ return (&kdb_thrctx->pcb_context[PCB_REG_S8]);
+ case 31:
+ return (&kdb_thrctx->pcb_context[PCB_REG_RA]);
+ case 37:
+ return (&kdb_thrctx->pcb_context[PCB_REG_PC]);
}
return (NULL);
}
diff --git a/sys/mips/mips/machdep.c b/sys/mips/mips/machdep.c
index 314bfd1..074b524 100644
--- a/sys/mips/mips/machdep.c
+++ b/sys/mips/mips/machdep.c
@@ -138,6 +138,7 @@ struct pcpu *pcpup = (struct pcpu *)pcpu_space;
vm_offset_t phys_avail[PHYS_AVAIL_ENTRIES + 2];
vm_offset_t physmem_desc[PHYS_AVAIL_ENTRIES + 2];
+vm_paddr_t dump_avail[PHYS_AVAIL_ENTRIES + 2];
#ifdef UNIMPLEMENTED
struct platform platform;
@@ -488,13 +489,6 @@ cpu_idle(int busy)
panic("ints disabled in idleproc!");
}
-void
-dumpsys(struct dumperinfo *di __unused)
-{
-
- printf("Kernel dumps not implemented on this architecture\n");
-}
-
int
cpu_idle_wakeup(int cpu)
{
diff --git a/sys/mips/mips/minidump_machdep.c b/sys/mips/mips/minidump_machdep.c
new file mode 100644
index 0000000..1ac384a
--- /dev/null
+++ b/sys/mips/mips/minidump_machdep.c
@@ -0,0 +1,340 @@
+/*-
+ * Copyright (c) 2010 Oleksandr Tymoshenko <gonzo@freebsd.org>
+ * Copyright (c) 2008 Semihalf, Grzegorz Bernacki
+ * 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 ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED 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.
+ *
+ * from: FreeBSD: src/sys/arm/arm/minidump_machdep.c v214223
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/cons.h>
+#include <sys/kernel.h>
+#include <sys/kerneldump.h>
+#include <sys/msgbuf.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <machine/pmap.h>
+#include <machine/atomic.h>
+#include <machine/elf.h>
+#include <machine/md_var.h>
+#include <machine/vmparam.h>
+#include <machine/minidump.h>
+#include <machine/cache.h>
+
+CTASSERT(sizeof(struct kerneldumpheader) == 512);
+
+/*
+ * Don't touch the first SIZEOF_METADATA bytes on the dump device. This
+ * is to protect us from metadata and to protect metadata from us.
+ */
+#define SIZEOF_METADATA (64*1024)
+
+uint32_t *vm_page_dump;
+int vm_page_dump_size;
+
+static struct kerneldumpheader kdh;
+static off_t dumplo;
+static off_t origdumplo;
+
+/* Handle chunked writes. */
+static uint64_t counter, progress;
+/* Just auxiliary bufffer */
+static char tmpbuffer[PAGE_SIZE];
+
+extern pd_entry_t *kernel_segmap;
+
+CTASSERT(sizeof(*vm_page_dump) == 4);
+
+static int
+is_dumpable(vm_paddr_t pa)
+{
+ int i;
+
+ for (i = 0; dump_avail[i] != 0 || dump_avail[i + 1] != 0; i += 2) {
+ if (pa >= dump_avail[i] && pa < dump_avail[i + 1])
+ return (1);
+ }
+ return (0);
+}
+
+static void
+dump_add_page(vm_paddr_t pa)
+{
+ int idx, bit;
+
+ pa >>= PAGE_SHIFT;
+ idx = pa >> 5; /* 2^5 = 32 */
+ bit = pa & 31;
+ atomic_set_int(&vm_page_dump[idx], 1ul << bit);
+}
+
+static void
+dump_drop_page(vm_paddr_t pa)
+{
+ int idx, bit;
+
+ pa >>= PAGE_SHIFT;
+ idx = pa >> 5; /* 2^5 = 32 */
+ bit = pa & 31;
+ atomic_clear_int(&vm_page_dump[idx], 1ul << bit);
+}
+
+#define PG2MB(pgs) (((pgs) + (1 << 8) - 1) >> 8)
+
+static int
+write_buffer(struct dumperinfo *di, char *ptr, size_t sz)
+{
+ size_t len;
+ int error, c;
+ u_int maxdumpsz;
+
+ maxdumpsz = di->maxiosize;
+
+ if (maxdumpsz == 0) /* seatbelt */
+ maxdumpsz = PAGE_SIZE;
+
+ error = 0;
+
+ while (sz) {
+ len = min(maxdumpsz, sz);
+ counter += len;
+ progress -= len;
+
+ if (counter >> 22) {
+ printf(" %jd", PG2MB(progress >> PAGE_SHIFT));
+ counter &= (1<<22) - 1;
+ }
+
+ if (ptr) {
+ error = dump_write(di, ptr, 0, dumplo, len);
+ if (error)
+ return (error);
+ dumplo += len;
+ ptr += len;
+ sz -= len;
+ } else {
+ panic("pa is not supported");
+ }
+
+ /* Check for user abort. */
+ c = cncheckc();
+ if (c == 0x03)
+ return (ECANCELED);
+ if (c != -1)
+ printf(" (CTRL-C to abort) ");
+ }
+
+ return (0);
+}
+
+void
+minidumpsys(struct dumperinfo *di)
+{
+ struct minidumphdr mdhdr;
+ uint64_t dumpsize;
+ uint32_t ptesize;
+ uint32_t bits;
+ vm_paddr_t pa;
+ vm_offset_t prev_pte = 0;
+ uint32_t count = 0;
+ vm_offset_t va;
+ pt_entry_t *pte;
+ int i, bit, error;
+ void *dump_va;
+
+ /* Flush cache */
+ mips_dcache_wbinv_all();
+
+ counter = 0;
+ /* Walk page table pages, set bits in vm_page_dump */
+ ptesize = 0;
+
+ for (va = VM_MIN_KERNEL_ADDRESS; va < kernel_vm_end; va += NBPDR) {
+ ptesize += PAGE_SIZE;
+ pte = pmap_pte(kernel_pmap, va);
+ KASSERT(pte != NULL, ("pte for %jx is NULL", (uintmax_t)va));
+ for (i = 0; i < NPTEPG; i++) {
+ if (pte_test(&pte[i], PTE_V)) {
+ pa = TLBLO_PTE_TO_PA(pte[i]);
+ if (is_dumpable(pa))
+ dump_add_page(pa);
+ }
+ }
+ }
+
+ /*
+ * Now mark pages from 0 to phys_avail[0], that's where kernel
+ * and pages allocated by pmap_steal reside
+ */
+ for (pa = 0; pa < phys_avail[0]; pa += PAGE_SIZE) {
+ if (is_dumpable(pa))
+ dump_add_page(pa);
+ }
+
+ /* Calculate dump size. */
+ dumpsize = ptesize;
+ dumpsize += round_page(msgbufp->msg_size);
+ dumpsize += round_page(vm_page_dump_size);
+
+ for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) {
+ bits = vm_page_dump[i];
+ while (bits) {
+ bit = ffs(bits) - 1;
+ pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) +
+ bit) * PAGE_SIZE;
+ /* Clear out undumpable pages now if needed */
+ if (is_dumpable(pa))
+ dumpsize += PAGE_SIZE;
+ else
+ dump_drop_page(pa);
+ bits &= ~(1ul << bit);
+ }
+ }
+
+ dumpsize += PAGE_SIZE;
+
+ /* Determine dump offset on device. */
+ if (di->mediasize < SIZEOF_METADATA + dumpsize + sizeof(kdh) * 2) {
+ error = ENOSPC;
+ goto fail;
+ }
+
+ origdumplo = dumplo = di->mediaoffset + di->mediasize - dumpsize;
+ dumplo -= sizeof(kdh) * 2;
+ progress = dumpsize;
+
+ /* Initialize mdhdr */
+ bzero(&mdhdr, sizeof(mdhdr));
+ strcpy(mdhdr.magic, MINIDUMP_MAGIC);
+ mdhdr.version = MINIDUMP_VERSION;
+ mdhdr.msgbufsize = msgbufp->msg_size;
+ mdhdr.bitmapsize = vm_page_dump_size;
+ mdhdr.ptesize = ptesize;
+ mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
+
+ mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_MIPS_VERSION, dumpsize,
+ di->blocksize);
+
+ printf("Physical memory: %ju MB\n",
+ (uintmax_t)ptoa((uintmax_t)physmem) / 1048576);
+ printf("Dumping %llu MB:", (long long)dumpsize >> 20);
+
+ /* Dump leader */
+ error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
+ if (error)
+ goto fail;
+ dumplo += sizeof(kdh);
+
+ /* Dump my header */
+ bzero(tmpbuffer, sizeof(tmpbuffer));
+ bcopy(&mdhdr, tmpbuffer, sizeof(mdhdr));
+ error = write_buffer(di, tmpbuffer, PAGE_SIZE);
+ if (error)
+ goto fail;
+
+ /* Dump msgbuf up front */
+ error = write_buffer(di, (char *)msgbufp->msg_ptr,
+ round_page(msgbufp->msg_size));
+ if (error)
+ goto fail;
+
+ /* Dump bitmap */
+ error = write_buffer(di, (char *)vm_page_dump,
+ round_page(vm_page_dump_size));
+ if (error)
+ goto fail;
+
+ /* Dump kernel page table pages */
+ for (va = VM_MIN_KERNEL_ADDRESS; va < kernel_vm_end; va += NBPDR) {
+ pte = pmap_pte(kernel_pmap, va);
+ KASSERT(pte != NULL, ("pte for %jx is NULL", (uintmax_t)va));
+ if (!count) {
+ prev_pte = (vm_offset_t)pte;
+ count++;
+ }
+ else {
+ if ((vm_offset_t)pte == (prev_pte + count * PAGE_SIZE))
+ count++;
+ else {
+ error = write_buffer(di, (char*)prev_pte,
+ count * PAGE_SIZE);
+ if (error)
+ goto fail;
+ count = 1;
+ prev_pte = (vm_offset_t)pte;
+ }
+ }
+ }
+
+ if (count) {
+ error = write_buffer(di, (char*)prev_pte, count * PAGE_SIZE);
+ if (error)
+ goto fail;
+ count = 0;
+ prev_pte = 0;
+ }
+
+ /* Dump memory chunks page by page*/
+ for (i = 0; i < vm_page_dump_size / sizeof(*vm_page_dump); i++) {
+ bits = vm_page_dump[i];
+ while (bits) {
+ bit = ffs(bits) - 1;
+ pa = (((uint64_t)i * sizeof(*vm_page_dump) * NBBY) +
+ bit) * PAGE_SIZE;
+ dump_va = pmap_kenter_temporary(pa, 0);
+ error = write_buffer(di, dump_va, PAGE_SIZE);
+ if (error)
+ goto fail;
+ pmap_kenter_temporary_free(pa);
+ bits &= ~(1ul << bit);
+ }
+ }
+
+ /* Dump trailer */
+ error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
+ if (error)
+ goto fail;
+ dumplo += sizeof(kdh);
+
+ /* Signal completion, signoff and exit stage left. */
+ dump_write(di, NULL, 0, 0, 0);
+ printf("\nDump complete\n");
+ return;
+
+fail:
+ if (error < 0)
+ error = -error;
+
+ if (error == ECANCELED)
+ printf("\nDump aborted\n");
+ else if (error == ENOSPC)
+ printf("\nDump failed. Partition too small.\n");
+ else
+ printf("\n** DUMP FAILED (ERROR %d) **\n", error);
+}
diff --git a/sys/mips/mips/vm_machdep.c b/sys/mips/mips/vm_machdep.c
index 95c9c64..73fab5a 100644
--- a/sys/mips/mips/vm_machdep.c
+++ b/sys/mips/mips/vm_machdep.c
@@ -121,8 +121,8 @@ cpu_fork(register struct thread *td1,register struct proc *p2,
/* Copy p1's pcb, note that in this case
* our pcb also includes the td_frame being copied
* too. The older mips2 code did an additional copy
- * of the td_frame, for us thats not needed any
- * longer (this copy does them both
+ * of the td_frame, for us that's not needed any
+ * longer (this copy does them both)
*/
bcopy(td1->td_pcb, pcb2, sizeof(*pcb2));
@@ -312,7 +312,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
* Initialize machine state (pcb and trap frame) for a new thread about to
* upcall. Put enough state in the new thread's PCB to get it to go back
* userret(), where we can intercept it again to set the return (upcall)
- * Address and stack, along with those from upcals that are from other sources
+ * Address and stack, along with those from upcalls that are from other sources
* such as those generated in thread_userret() itself.
*/
void
@@ -334,7 +334,7 @@ cpu_set_upcall(struct thread *td, struct thread *td0)
* at this time (see the matching comment below for
* more analysis) (need a good safe default).
* In MIPS, the trapframe is the first element of the PCB
- * and gets copied when we copy the PCB. No seperate copy
+ * and gets copied when we copy the PCB. No separate copy
* is needed.
*/
bcopy(td0->td_pcb, pcb2, sizeof(*pcb2));
diff --git a/sys/modules/acpi/Makefile b/sys/modules/acpi/Makefile
index a68504f..9390064 100644
--- a/sys/modules/acpi/Makefile
+++ b/sys/modules/acpi/Makefile
@@ -1,10 +1,6 @@
# $FreeBSD$
-.if ${MACHINE} == "i386"
-SUBDIR= acpi
-.endif
-
-SUBDIR+= acpi_asus acpi_fujitsu acpi_hp acpi_ibm \
+SUBDIR= acpi_asus acpi_fujitsu acpi_hp acpi_ibm \
acpi_panasonic acpi_sony acpi_toshiba acpi_video \
acpi_dock acpi_wmi aibs
diff --git a/sys/modules/acpi/acpi/Makefile b/sys/modules/acpi/acpi/Makefile
index c98e91f..ce1e572 100644
--- a/sys/modules/acpi/acpi/Makefile
+++ b/sys/modules/acpi/acpi/Makefile
@@ -22,7 +22,8 @@
${.CURDIR}/../../../pci \
${.CURDIR}/../../../dev/acpica \
${.CURDIR}/../../../dev/acpica/Osd \
- ${.CURDIR}/../../../${MACHINE_CPUARCH}/acpica
+ ${.CURDIR}/../../../${MACHINE_CPUARCH}/acpica \
+ ${.CURDIR}/../../../x86/acpica
KMOD= acpi
@@ -95,7 +96,7 @@ opt_ddb.h: Makefile
.endif
# Machine-specific code such as sleep/wakeup
-SRCS+= acpi_machdep.c acpi_wakecode.h acpi_wakeup.c
+SRCS+= acpi_apm.c acpi_machdep.c acpi_wakecode.h acpi_wakeup.c
SRCS+= assym.s madt.c
CLEANFILES+= acpi_wakecode.bin acpi_wakecode.h acpi_wakecode.o
diff --git a/sys/net/vnet.h b/sys/net/vnet.h
index 0baac27..1c8d1fe 100644
--- a/sys/net/vnet.h
+++ b/sys/net/vnet.h
@@ -95,7 +95,9 @@ struct vnet {
* Location of the kernel's 'set_vnet' linker set.
*/
extern uintptr_t *__start_set_vnet;
+__GLOBL(__start_set_vnet);
extern uintptr_t *__stop_set_vnet;
+__GLOBL(__stop_set_vnet);
#define VNET_START (uintptr_t)&__start_set_vnet
#define VNET_STOP (uintptr_t)&__stop_set_vnet
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index ae5354e..be85af4 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -874,10 +874,6 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
}
}
if (laddr.s_addr == INADDR_ANY) {
- error = in_pcbladdr(inp, &faddr, &laddr, cred);
- if (error)
- return (error);
-
/*
* If the destination address is multicast and an outgoing
* interface has been set as a multicast option, use the
@@ -902,9 +898,12 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
laddr = ia->ia_addr.sin_addr;
IN_IFADDR_RUNLOCK();
}
+ } else {
+ error = in_pcbladdr(inp, &faddr, &laddr, cred);
+ if (error)
+ return (error);
}
}
-
oinp = in_pcblookup_hash(inp->inp_pcbinfo, faddr, fport, laddr, lport,
0, NULL);
if (oinp != NULL) {
diff --git a/sys/netinet/sctp.h b/sys/netinet/sctp.h
index 1335e82..69473e2 100644
--- a/sys/netinet/sctp.h
+++ b/sys/netinet/sctp.h
@@ -108,7 +108,7 @@ struct sctp_paramhdr {
#define SCTP_MAX_BURST 0x00000019 /* rw */
/* assoc level context */
#define SCTP_CONTEXT 0x0000001a /* rw */
-/* explict EOR signalling */
+/* explicit EOR signalling */
#define SCTP_EXPLICIT_EOR 0x0000001b
#define SCTP_REUSE_PORT 0x0000001c /* rw */
#define SCTP_AUTH_DEACTIVATE_KEY 0x0000001d
@@ -131,9 +131,9 @@ struct sctp_paramhdr {
* Blocking I/O is enabled on any TCP type socket by default. For the UDP
* model if this is turned on then the socket buffer is shared for send
* resources amongst all associations. The default for the UDP model is that
- * is SS_NBIO is set. Which means all associations have a seperate send
+ * is SS_NBIO is set. Which means all associations have a separate send
* limit BUT they will NOT ever BLOCK instead you will get an error back
- * EAGAIN if you try to send to much. If you want the blocking symantics you
+ * EAGAIN if you try to send too much. If you want the blocking semantics you
* set this option at the cost of sharing one socket send buffer size amongst
* all associations. Peeled off sockets turn this option off and block. But
* since both TCP and peeled off sockets have only one assoc per socket this
@@ -141,7 +141,7 @@ struct sctp_paramhdr {
* model OR peeled off UDP model, but we do allow you to do so. You just use
* the normal syscall to toggle SS_NBIO the way you want.
*
- * Blocking I/O is controled by the SS_NBIO flag on the socket state so_state
+ * Blocking I/O is controlled by the SS_NBIO flag on the socket state so_state
* field.
*/
@@ -166,7 +166,7 @@ struct sctp_paramhdr {
/* Special hook for dynamically setting primary for all assoc's,
- * this is a write only option that requires root privledge.
+ * this is a write only option that requires root privilege.
*/
#define SCTP_SET_DYNAMIC_PRIMARY 0x00002001
@@ -181,7 +181,7 @@ struct sctp_paramhdr {
* to. The endpoint, before binding, may select
* the "default" VRF it is in by using a set socket
* option with SCTP_VRF_ID. This will also
- * get propegated to the default VRF. Once the
+ * get propagated to the default VRF. Once the
* endpoint binds an address then it CANNOT add
* additional VRF's to become a Multi-VRF endpoint.
*
@@ -308,7 +308,7 @@ struct sctp_paramhdr {
#define SCTP_CAUSE_UNSUPPORTED_HMACID 0x0105
/*
- * error cause parameters (user visisble)
+ * error cause parameters (user visible)
*/
struct sctp_error_cause {
uint16_t code;
diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c
index 6cae72e..05b40f7 100644
--- a/sys/netinet/sctp_indata.c
+++ b/sys/netinet/sctp_indata.c
@@ -4369,7 +4369,7 @@ again:
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
sctp_send_shutdown_ack(stcb,
stcb->asoc.primary_destination);
-
+ sctp_stop_timers_for_shutdown(stcb);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK,
stcb->sctp_ep, stcb, asoc->primary_destination);
}
@@ -5081,7 +5081,7 @@ done_with_it:
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
sctp_send_shutdown_ack(stcb,
stcb->asoc.primary_destination);
-
+ sctp_stop_timers_for_shutdown(stcb);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK,
stcb->sctp_ep, stcb, asoc->primary_destination);
return;
diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c
index e30f12b..ad4209f 100644
--- a/sys/netinet/sctp_input.c
+++ b/sys/netinet/sctp_input.c
@@ -908,9 +908,7 @@ sctp_handle_shutdown(struct sctp_shutdown_chunk *cp,
}
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT);
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
- sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_INPUT + SCTP_LOC_7);
- /* start SHUTDOWN timer */
+ sctp_stop_timers_for_shutdown(stcb);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, stcb->sctp_ep,
stcb, net);
}
diff --git a/sys/netinet/sctp_os_bsd.h b/sys/netinet/sctp_os_bsd.h
index 883d6dd..171c38e 100644
--- a/sys/netinet/sctp_os_bsd.h
+++ b/sys/netinet/sctp_os_bsd.h
@@ -316,7 +316,7 @@ typedef struct callout sctp_os_timer_t;
}
/* We make it so if you have up to 4 threads
- * writting based on the default size of
+ * writing based on the default size of
* the packet log 65 k, that would be
* 4 16k packets before we would hit
* a problem.
@@ -353,7 +353,7 @@ typedef struct callout sctp_os_timer_t;
/* For BSD this just accesses the M_PKTHDR length
* so it operates on an mbuf with hdr flag. Other
- * O/S's may have seperate packet header and mbuf
+ * O/S's may have separate packet header and mbuf
* chain pointers.. thus the macro.
*/
#define SCTP_HEADER_TO_CHAIN(m) (m)
diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c
index 1e68399..50820b7 100644
--- a/sys/netinet/sctp_output.c
+++ b/sys/netinet/sctp_output.c
@@ -10118,19 +10118,18 @@ sctp_send_sack(struct sctp_tcb *stcb)
}
}
- if (((type == SCTP_SELECTIVE_ACK) &&
- (((asoc->mapping_array[0] | asoc->nr_mapping_array[0]) & 0x01) == 0x00)) ||
- ((type == SCTP_NR_SELECTIVE_ACK) &&
- ((asoc->mapping_array[0] & 0x01) == 0x00))) {
- sel_start = 0;
- } else {
- sel_start = 1;
- }
if (compare_with_wrap(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, MAX_TSN)) {
offset = 1;
} else {
offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn;
}
+ if ((offset == 1) ||
+ ((type == SCTP_NR_SELECTIVE_ACK) &&
+ ((asoc->mapping_array[0] & (1 << (1 - offset))) == 0))) {
+ sel_start = 0;
+ } else {
+ sel_start = 1;
+ }
if (((type == SCTP_SELECTIVE_ACK) &&
compare_with_wrap(highest_tsn, asoc->cumulative_tsn, MAX_TSN)) ||
((type == SCTP_NR_SELECTIVE_ACK) &&
@@ -10200,7 +10199,7 @@ sctp_send_sack(struct sctp_tcb *stcb)
siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_nr_map + 7) / 8;
}
- if ((asoc->nr_mapping_array[0] & 0x01) == 0x00) {
+ if ((asoc->nr_mapping_array[0] & (1 << (1 - offset))) == 0) {
sel_start = 0;
} else {
sel_start = 1;
diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c
index 6e32439..7e305c4 100644
--- a/sys/netinet/sctp_pcb.c
+++ b/sys/netinet/sctp_pcb.c
@@ -107,7 +107,7 @@ sctp_fill_pcbinfo(struct sctp_pcbinfo *spcb)
* ... +--ifa-> ifa -> ifa
* vrf
*
- * We keep these seperate lists since the SCTP subsystem will
+ * We keep these separate lists since the SCTP subsystem will
* point to these from its source address selection nets structure.
* When an address is deleted it does not happen right away on
* the SCTP side, it gets scheduled. What we do when a
@@ -191,7 +191,7 @@ sctp_find_ifn(void *ifn, uint32_t ifn_index)
struct sctp_ifnlist *hash_ifn_head;
/*
- * We assume the lock is held for the addresses if thats wrong
+ * We assume the lock is held for the addresses if that's wrong
* problems could occur :-)
*/
hash_ifn_head = &SCTP_BASE_INFO(vrf_ifn_hash)[(ifn_index & SCTP_BASE_INFO(vrf_ifn_hashmark))];
@@ -327,7 +327,7 @@ sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr,
len1 = strlen(if_name);
len2 = strlen(sctp_ifap->ifn_p->ifn_name);
if (len1 != len2) {
- SCTPDBG(SCTP_DEBUG_PCB4, "IFN of ifa names different lenght %d vs %d - ignored\n",
+ SCTPDBG(SCTP_DEBUG_PCB4, "IFN of ifa names different length %d vs %d - ignored\n",
len1, len2);
goto out;
}
@@ -380,7 +380,7 @@ sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr,
len1 = strlen(if_name);
len2 = strlen(sctp_ifap->ifn_p->ifn_name);
if (len1 != len2) {
- SCTPDBG(SCTP_DEBUG_PCB4, "IFN of ifa names different lenght %d vs %d - ignored\n",
+ SCTPDBG(SCTP_DEBUG_PCB4, "IFN of ifa names different length %d vs %d - ignored\n",
len1, len2);
goto out;
}
@@ -567,8 +567,8 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index,
} else {
if (sctp_ifap->ifn_p) {
/*
- * The last IFN gets the address, removee
- * the old one
+ * The last IFN gets the address, remove the
+ * old one
*/
SCTPDBG(SCTP_DEBUG_PCB4, "Moving ifa %p from %s (0x%x) to %s (0x%x)\n",
sctp_ifap, sctp_ifap->ifn_p->ifn_name,
@@ -849,7 +849,7 @@ sctp_tcb_special_locate(struct sctp_inpcb **inp_p, struct sockaddr *from,
} else {
return NULL;
}
- ephead = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport), SCTP_BASE_INFO(hashtcpmark))];
+ ephead = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport | rport), SCTP_BASE_INFO(hashtcpmark))];
/*
* Ok now for each of the guys in this bucket we must look and see:
* - Does the remote port match. - Does there single association's
@@ -1515,7 +1515,7 @@ sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head,
int fnd;
/*
- * Endpoing probe expects that the INP_INFO is locked.
+ * Endpoint probe expects that the INP_INFO is locked.
*/
sin = NULL;
#ifdef INET6
@@ -1771,6 +1771,7 @@ sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock,
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
int lport;
+ unsigned int i;
if (nam->sa_family == AF_INET) {
sin = (struct sockaddr_in *)nam;
@@ -1797,17 +1798,22 @@ sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock,
/*
* If the TCP model exists it could be that the main listening
- * endpoint is gone but there exists a connected socket for this guy
- * yet. If so we can return the first one that we find. This may NOT
- * be the correct one so the caller should be wary on the return
- * INP. Currently the onlyc caller that sets this flag is in bindx
- * where we are verifying that a user CAN bind the address. He
- * either has bound it already, or someone else has, or its open to
- * bind, so this is good enough.
+ * endpoint is gone but there still exists a connected socket for
+ * this guy. If so we can return the first one that we find. This
+ * may NOT be the correct one so the caller should be wary on the
+ * returned INP. Currently the only caller that sets find_tcp_pool
+ * is in bindx where we are verifying that a user CAN bind the
+ * address. He either has bound it already, or someone else has, or
+ * its open to bind, so this is good enough.
*/
if (inp == NULL && find_tcp_pool) {
- head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR(lport, SCTP_BASE_INFO(hashtcpmark))];
- inp = sctp_endpoint_probe(nam, head, lport, vrf_id);
+ for (i = 0; i < SCTP_BASE_INFO(hashtcpmark) + 1; i++) {
+ head = &SCTP_BASE_INFO(sctp_tcpephash)[i];
+ inp = sctp_endpoint_probe(nam, head, lport, vrf_id);
+ if (inp) {
+ break;
+ }
+ }
}
if (inp) {
SCTP_INP_INCR_REF(inp);
@@ -2005,7 +2011,7 @@ sctp_findassoc_by_vtag(struct sockaddr *from, struct sockaddr *to, uint32_t vtag
}
if (remote_tag) {
/*
- * If we have both vtags thats all we match
+ * If we have both vtags that's all we match
* on
*/
if (stcb->asoc.peer_vtag == remote_tag) {
@@ -2183,7 +2189,7 @@ sctp_findassociation_addr(struct mbuf *m, int iphlen, int offset,
* association that is linked to an existing
* association that is under the TCP pool (i.e. no
* listener exists). The endpoint finding routine
- * will always find a listner before examining the
+ * will always find a listener before examining the
* TCP pool.
*/
if (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) {
@@ -2603,8 +2609,7 @@ sctp_move_pcb_and_assoc(struct sctp_inpcb *old_inp, struct sctp_inpcb *new_inp,
LIST_REMOVE(stcb, sctp_tcbasocidhash);
}
/* Now insert the new_inp into the TCP connected hash */
- head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport),
- SCTP_BASE_INFO(hashtcpmark))];
+ head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport | rport), SCTP_BASE_INFO(hashtcpmark))];
LIST_INSERT_HEAD(head, new_inp, sctp_hash);
/* Its safe to access */
@@ -3089,12 +3094,10 @@ continue_anyway:
/* find the bucket */
if (port_reuse_active) {
/* Put it into tcp 1-2-1 hash */
- head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport),
- SCTP_BASE_INFO(hashtcpmark))];
+ head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR(lport, SCTP_BASE_INFO(hashtcpmark))];
inp->sctp_flags |= SCTP_PCB_FLAGS_IN_TCPPOOL;
} else {
- head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(lport,
- SCTP_BASE_INFO(hashmark))];
+ head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(lport, SCTP_BASE_INFO(hashmark))];
}
/* put it in the bucket */
LIST_INSERT_HEAD(head, inp, sctp_hash);
@@ -3554,7 +3557,7 @@ sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
SCTP_INP_INFO_WUNLOCK();
/*
* Now we release all locks. Since this INP cannot be found anymore
- * except possbily by the kill timer that might be running. We call
+ * except possibly by the kill timer that might be running. We call
* the drain function here. It should hit the case were it sees the
* ACTIVE flag cleared and exit out freeing us to proceed and
* destroy everything.
@@ -3716,8 +3719,8 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
{
/*
* The following is redundant to the same lines in the
- * sctp_aloc_assoc() but is needed since other's call the add
- * address function
+ * sctp_aloc_assoc() but is needed since others call the add address
+ * function
*/
struct sctp_nets *net, *netfirst;
int addr_inscope;
@@ -4034,7 +4037,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
(stcb->asoc.primary_destination)) {
/*
* first one on the list is NOT the primary sctp_cmpaddr()
- * is much more efficent if the primary is the first on the
+ * is much more efficient if the primary is the first on the
* list, make it so.
*/
TAILQ_REMOVE(&stcb->asoc.nets,
@@ -4176,7 +4179,7 @@ sctp_aloc_assoc(struct sctp_inpcb *inp, struct sockaddr *firstaddr,
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
/*
* If you have not performed a bind, then we need to do the
- * ephemerial bind for you.
+ * ephemeral bind for you.
*/
if ((err = sctp_inpcb_bind(inp->sctp_socket,
(struct sockaddr *)NULL,
@@ -5159,10 +5162,10 @@ sctp_free_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int from_inpcbfre
SCTP_INP_RUNLOCK(inp);
/*
* This will start the kill timer (if we are the
- * lastone) since we hold an increment yet. But this
- * is the only safe way to do this since otherwise
- * if the socket closes at the same time we are here
- * we might collide in the cleanup.
+ * last one) since we hold an increment yet. But
+ * this is the only safe way to do this since
+ * otherwise if the socket closes at the same time
+ * we are here we might collide in the cleanup.
*/
sctp_inpcb_free(inp,
SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
@@ -6461,7 +6464,7 @@ sctp_set_primary_addr(struct sctp_tcb *stcb, struct sockaddr *sa,
if (net != stcb->asoc.primary_destination) {
/*
* first one on the list is NOT the primary
- * sctp_cmpaddr() is much more efficent if the
+ * sctp_cmpaddr() is much more efficient if the
* primary is the first on the list, make it so.
*/
TAILQ_REMOVE(&stcb->asoc.nets, stcb->asoc.primary_destination, sctp_next);
@@ -6676,12 +6679,12 @@ sctp_drain_mbufs(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
}
/*
* Another issue, in un-setting the TSN's in the mapping array we
- * DID NOT adjust the higest_tsn marker. This will cause one of two
- * things to occur. It may cause us to do extra work in checking for
- * our mapping array movement. More importantly it may cause us to
- * SACK every datagram. This may not be a bad thing though since we
- * will recover once we get our cum-ack above and all this stuff we
- * dumped recovered.
+ * DID NOT adjust the highest_tsn marker. This will cause one of
+ * two things to occur. It may cause us to do extra work in checking
+ * for our mapping array movement. More importantly it may cause us
+ * to SACK every datagram. This may not be a bad thing though since
+ * we will recover once we get our cum-ack above and all this stuff
+ * we dumped recovered.
*/
}
diff --git a/sys/netinet/sctp_timer.c b/sys/netinet/sctp_timer.c
index 949dd2f..7e9dd29 100644
--- a/sys/netinet/sctp_timer.c
+++ b/sys/netinet/sctp_timer.c
@@ -291,6 +291,10 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
return (0);
}
+/*
+ * sctp_find_alternate_net() returns a non-NULL pointer as long
+ * the argument net is non-NULL.
+ */
struct sctp_nets *
sctp_find_alternate_net(struct sctp_tcb *stcb,
struct sctp_nets *net,
@@ -440,8 +444,7 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
else if (mode == 1) {
TAILQ_FOREACH(mnet, &stcb->asoc.nets, sctp_next) {
if (((mnet->dest_state & SCTP_ADDR_REACHABLE) != SCTP_ADDR_REACHABLE) ||
- (mnet->dest_state & SCTP_ADDR_UNCONFIRMED)
- ) {
+ (mnet->dest_state & SCTP_ADDR_UNCONFIRMED)) {
/*
* will skip ones that are not-reachable or
* unconfirmed
@@ -505,12 +508,10 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
}
alt->src_addr_selected = 0;
}
- if (
- ((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) &&
- (alt->ro.ro_rt != NULL) &&
/* sa_ignore NO_NULL_CHK */
- (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))
- ) {
+ if (((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) &&
+ (alt->ro.ro_rt != NULL) &&
+ (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))) {
/* Found a reachable address */
break;
}
@@ -549,8 +550,6 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
return (alt);
}
-
-
static void
sctp_backoff_on_timeout(struct sctp_tcb *stcb,
struct sctp_nets *net,
@@ -1021,8 +1020,7 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
* used, then pick dest with largest ssthresh for any
* retransmission.
*/
- alt = net;
- alt = sctp_find_alternate_net(stcb, alt, 1);
+ alt = sctp_find_alternate_net(stcb, net, 1);
/*
* CUCv2: If a different dest is picked for the
* retransmission, then new (rtx-)pseudo_cumack needs to be
@@ -1213,7 +1211,7 @@ sctp_t1init_timer(struct sctp_inpcb *inp,
struct sctp_nets *alt;
alt = sctp_find_alternate_net(stcb, stcb->asoc.primary_destination, 0);
- if ((alt != NULL) && (alt != stcb->asoc.primary_destination)) {
+ if (alt != stcb->asoc.primary_destination) {
sctp_move_chunks_from_net(stcb, stcb->asoc.primary_destination);
stcb->asoc.primary_destination = alt;
}
@@ -1480,6 +1478,7 @@ sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* For the shutdown and shutdown-ack, we do not keep one around on the
* control queue. This means we must generate a new one and call the general
* chunk output routine, AFTER having done threshold management.
+ * It is assumed that net is non-NULL.
*/
int
sctp_shutdown_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
@@ -1492,18 +1491,13 @@ sctp_shutdown_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* Assoc is over */
return (1);
}
+ sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
/* second select an alternative */
alt = sctp_find_alternate_net(stcb, net, 0);
/* third generate a shutdown into the queue for out net */
- if (alt) {
- sctp_send_shutdown(stcb, alt);
- } else {
- /*
- * if alt is NULL, there is no dest to send to??
- */
- return (0);
- }
+ sctp_send_shutdown(stcb, alt);
+
/* fourth restart timer */
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, inp, stcb, alt);
return (0);
@@ -1520,6 +1514,7 @@ sctp_shutdownack_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* Assoc is over */
return (1);
}
+ sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
/* second select an alternative */
alt = sctp_find_alternate_net(stcb, net, 0);
@@ -1675,70 +1670,6 @@ sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
return (0);
}
-int
-sctp_is_hb_timer_running(struct sctp_tcb *stcb)
-{
- if (SCTP_OS_TIMER_PENDING(&stcb->asoc.hb_timer.timer)) {
- /* its running */
- return (1);
- } else {
- /* nope */
- return (0);
- }
-}
-
-int
-sctp_is_sack_timer_running(struct sctp_tcb *stcb)
-{
- if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
- /* its running */
- return (1);
- } else {
- /* nope */
- return (0);
- }
-}
-
-#define SCTP_NUMBER_OF_MTU_SIZES 18
-static uint32_t mtu_sizes[] = {
- 68,
- 296,
- 508,
- 512,
- 544,
- 576,
- 1006,
- 1492,
- 1500,
- 1536,
- 2002,
- 2048,
- 4352,
- 4464,
- 8166,
- 17914,
- 32000,
- 65535
-};
-
-
-static uint32_t
-sctp_getnext_mtu(struct sctp_inpcb *inp, uint32_t cur_mtu)
-{
- /* select another MTU that is just bigger than this one */
- int i;
-
- for (i = 0; i < SCTP_NUMBER_OF_MTU_SIZES; i++) {
- if (cur_mtu < mtu_sizes[i]) {
- /* no max_mtu is bigger than this one */
- return (mtu_sizes[i]);
- }
- }
- /* here return the highest allowable */
- return (cur_mtu);
-}
-
-
void
sctp_pathmtu_timer(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
@@ -1746,7 +1677,7 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
{
uint32_t next_mtu, mtu;
- next_mtu = sctp_getnext_mtu(inp, net->mtu);
+ next_mtu = sctp_get_next_mtu(inp, net->mtu);
if ((next_mtu > net->mtu) && (net->port == 0)) {
if ((net->src_addr_selected == 0) ||
diff --git a/sys/netinet/sctp_timer.h b/sys/netinet/sctp_timer.h
index c3b3188..a26ad72 100644
--- a/sys/netinet/sctp_timer.h
+++ b/sys/netinet/sctp_timer.h
@@ -65,9 +65,6 @@ int
sctp_heartbeat_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *, int);
-int sctp_is_hb_timer_running(struct sctp_tcb *stcb);
-int sctp_is_sack_timer_running(struct sctp_tcb *stcb);
-
int
sctp_cookie_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
diff --git a/sys/netinet/sctp_uio.h b/sys/netinet/sctp_uio.h
index 1cd5465..c901521 100644
--- a/sys/netinet/sctp_uio.h
+++ b/sys/netinet/sctp_uio.h
@@ -80,7 +80,7 @@ struct sctp_initmsg {
/* We add 96 bytes to the size of sctp_sndrcvinfo.
* This makes the current structure 128 bytes long
* which is nicely 64 bit aligned but also has room
- * for us to add more and keep ABI compatability.
+ * for us to add more and keep ABI compatibility.
* For example, already we have the sctp_extrcvinfo
* when enabled which is 48 bytes.
*/
@@ -304,7 +304,7 @@ struct sctp_setadaptation {
uint32_t ssb_adaptation_ind;
};
-/* compatable old spelling */
+/* compatible old spelling */
struct sctp_adaption_event {
uint16_t sai_type;
uint16_t sai_flags;
@@ -396,7 +396,7 @@ union sctp_notification {
struct sctp_send_failed sn_send_failed;
struct sctp_shutdown_event sn_shutdown_event;
struct sctp_adaptation_event sn_adaptation_event;
- /* compatability same as above */
+ /* compatibility same as above */
struct sctp_adaption_event sn_adaption_event;
struct sctp_pdapi_event sn_pdapi_event;
struct sctp_authkey_event sn_auth_event;
@@ -417,7 +417,7 @@ union sctp_notification {
#define SCTP_AUTHENTICATION_EVENT 0x0008
#define SCTP_STREAM_RESET_EVENT 0x0009
#define SCTP_SENDER_DRY_EVENT 0x000a
-#define SCTP__NOTIFICATIONS_STOPPED_EVENT 0x000b /* we dont send this */
+#define SCTP__NOTIFICATIONS_STOPPED_EVENT 0x000b /* we don't send this */
/*
* socket option structs
*/
@@ -893,7 +893,7 @@ struct sctpstat {
uint32_t sctps_earlyfrstrid;
uint32_t sctps_earlyfrstrout;
uint32_t sctps_earlyfrstrtmr;
- /* otheres */
+ /* others */
uint32_t sctps_hdrops; /* packet shorter than header */
uint32_t sctps_badsum; /* checksum error */
uint32_t sctps_noport; /* no endpoint for port */
@@ -904,8 +904,8 @@ struct sctpstat {
* RTT window */
uint32_t sctps_markedretrans;
uint32_t sctps_naglesent; /* nagle allowed sending */
- uint32_t sctps_naglequeued; /* nagle does't allow sending */
- uint32_t sctps_maxburstqueued; /* max burst dosn't allow sending */
+ uint32_t sctps_naglequeued; /* nagle doesn't allow sending */
+ uint32_t sctps_maxburstqueued; /* max burst doesn't allow sending */
uint32_t sctps_ifnomemqueued; /* look ahead tells us no memory in
* interface ring buffer OR we had a
* send error and are queuing one
@@ -931,7 +931,7 @@ struct sctpstat {
uint32_t sctps_wu_sacks_sent; /* Window Update only sacks sent */
uint32_t sctps_sends_with_flags; /* number of sends with
* sinfo_flags !=0 */
- uint32_t sctps_sends_with_unord /* number of undordered sends */ ;
+ uint32_t sctps_sends_with_unord; /* number of unordered sends */
uint32_t sctps_sends_with_eof; /* number of sends with EOF flag set */
uint32_t sctps_sends_with_abort; /* number of sends with ABORT
* flag set */
@@ -943,7 +943,7 @@ struct sctpstat {
* with peek */
uint32_t sctps_cached_chk; /* Number of cached chunks used */
uint32_t sctps_cached_strmoq; /* Number of cached stream oq's used */
- uint32_t sctps_left_abandon; /* Number of unread message abandonded
+ uint32_t sctps_left_abandon; /* Number of unread messages abandoned
* by close */
uint32_t sctps_send_burst_avoid; /* Unused */
uint32_t sctps_send_cwnd_avoid; /* Send cwnd full avoidance, already
diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c
index 627d1ee..266c08c 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -194,7 +194,7 @@ sctp_notify_mbuf(struct sctp_inpcb *inp,
* mtu is. Rats we will have to guess (in a educated fashion
* of course)
*/
- nxtsz = find_next_best_mtu(totsz);
+ nxtsz = sctp_get_prev_mtu(totsz);
}
/* Stop any PMTU timer */
if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c
index de9401f..76c58a5 100644
--- a/sys/netinet/sctputil.c
+++ b/sys/netinet/sctputil.c
@@ -50,8 +50,6 @@ __FBSDID("$FreeBSD$");
#include <netinet/sctp_cc_functions.h>
#include <netinet/sctp_bsd_addr.h>
-#define NUMBER_OF_MTU_SIZES 18
-
#ifndef KTR_SCTP
#define KTR_SCTP KTR_SUBSYS
@@ -725,10 +723,35 @@ sctp_audit_log(uint8_t ev, uint8_t fd)
#endif
/*
+ * sctp_stop_timers_for_shutdown() should be called
+ * when entering the SHUTDOWN_SENT or SHUTDOWN_ACK_SENT
+ * state to make sure that all timers are stopped.
+ */
+void
+sctp_stop_timers_for_shutdown(struct sctp_tcb *stcb)
+{
+ struct sctp_association *asoc;
+ struct sctp_nets *net;
+
+ asoc = &stcb->asoc;
+
+ (void)SCTP_OS_TIMER_STOP(&asoc->hb_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&asoc->dack_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&asoc->asconf_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&asoc->autoclose_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&asoc->delayed_event_timer.timer);
+ TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
+ (void)SCTP_OS_TIMER_STOP(&net->fr_timer.timer);
+ (void)SCTP_OS_TIMER_STOP(&net->pmtu_timer.timer);
+ }
+}
+
+/*
* a list of sizes based on typical mtu's, used only if next hop size not
* returned.
*/
-static int sctp_mtu_sizes[] = {
+static uint32_t sctp_mtu_sizes[] = {
68,
296,
508,
@@ -749,45 +772,42 @@ static int sctp_mtu_sizes[] = {
65535
};
-void
-sctp_stop_timers_for_shutdown(struct sctp_tcb *stcb)
+/*
+ * Return the largest MTU smaller than val. If there is no
+ * entry, just return val.
+ */
+uint32_t
+sctp_get_prev_mtu(uint32_t val)
{
- struct sctp_association *asoc;
- struct sctp_nets *net;
+ uint32_t i;
- asoc = &stcb->asoc;
-
- (void)SCTP_OS_TIMER_STOP(&asoc->hb_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&asoc->dack_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&asoc->asconf_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&asoc->autoclose_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&asoc->delayed_event_timer.timer);
- TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
- (void)SCTP_OS_TIMER_STOP(&net->fr_timer.timer);
- (void)SCTP_OS_TIMER_STOP(&net->pmtu_timer.timer);
+ if (val <= sctp_mtu_sizes[0]) {
+ return (val);
+ }
+ for (i = 1; i < (sizeof(sctp_mtu_sizes) / sizeof(uint32_t)); i++) {
+ if (val <= sctp_mtu_sizes[i]) {
+ break;
+ }
}
+ return (sctp_mtu_sizes[i - 1]);
}
-int
-find_next_best_mtu(int totsz)
+/*
+ * Return the smallest MTU larger than val. If there is no
+ * entry, just return val.
+ */
+uint32_t
+sctp_get_next_mtu(struct sctp_inpcb *inp, uint32_t val)
{
- int i, perfer;
+ /* select another MTU that is just bigger than this one */
+ uint32_t i;
- /*
- * if we are in here we must find the next best fit based on the
- * size of the dg that failed to be sent.
- */
- perfer = 0;
- for (i = 0; i < NUMBER_OF_MTU_SIZES; i++) {
- if (totsz < sctp_mtu_sizes[i]) {
- perfer = i - 1;
- if (perfer < 0)
- perfer = 0;
- break;
+ for (i = 0; i < (sizeof(sctp_mtu_sizes) / sizeof(uint32_t)); i++) {
+ if (val < sctp_mtu_sizes[i]) {
+ return (sctp_mtu_sizes[i]);
}
}
- return (sctp_mtu_sizes[perfer]);
+ return (val);
}
void
@@ -2806,6 +2826,7 @@ sctp_notify_assoc_change(uint32_t event, struct sctp_tcb *stcb,
}
}
#endif
+ socantrcvmore(stcb->sctp_socket);
sorwakeup(stcb->sctp_socket);
sowwakeup(stcb->sctp_socket);
#if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
diff --git a/sys/netinet/sctputil.h b/sys/netinet/sctputil.h
index dfd552a..d109ec2 100644
--- a/sys/netinet/sctputil.h
+++ b/sys/netinet/sctputil.h
@@ -124,7 +124,8 @@ sctp_append_to_readq(struct sctp_inpcb *inp,
void sctp_iterator_worker(void);
-int find_next_best_mtu(int);
+uint32_t sctp_get_prev_mtu(uint32_t);
+uint32_t sctp_get_next_mtu(struct sctp_inpcb *, uint32_t);
void
sctp_timeout_handler(void *);
diff --git a/sys/pc98/include/apm_bios.h b/sys/pc98/include/apm_bios.h
index 261ae37..77d99c1 100644
--- a/sys/pc98/include/apm_bios.h
+++ b/sys/pc98/include/apm_bios.h
@@ -32,7 +32,7 @@
* PC98 machines implement APM bios in nearly the same was as i386 machines,
* so include the i386 version and note the changes here.
*/
-#include <i386/apm_bios.h>
+#include <x86/apm_bios.h>
/*
* APM BIOS and interrupt are different on pc98
diff --git a/sys/pc98/include/mptable.h b/sys/pc98/include/mptable.h
deleted file mode 100644
index 2f6fb2d..0000000
--- a/sys/pc98/include/mptable.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/*-
- * This file is in the public domain.
- */
-/* $FreeBSD$ */
-
-#include <i386/mptable.h>
diff --git a/sys/pc98/include/mutex.h b/sys/pc98/include/mutex.h
deleted file mode 100644
index a79c8f7..0000000
--- a/sys/pc98/include/mutex.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/*-
- * This file is in the public domain.
- */
-/* $FreeBSD$ */
-
-#include <i386/mutex.h>
diff --git a/sys/pci/if_rlreg.h b/sys/pci/if_rlreg.h
index 0b29474..9de7217 100644
--- a/sys/pci/if_rlreg.h
+++ b/sys/pci/if_rlreg.h
@@ -36,210 +36,211 @@
* RealTek 8129/8139 register offsets
*/
#define RL_IDR0 0x0000 /* ID register 0 (station addr) */
-#define RL_IDR1 0x0001 /* Must use 32-bit accesses (?) */
-#define RL_IDR2 0x0002
-#define RL_IDR3 0x0003
-#define RL_IDR4 0x0004
-#define RL_IDR5 0x0005
+#define RL_IDR1 0x0001 /* Must use 32-bit accesses (?) */
+#define RL_IDR2 0x0002
+#define RL_IDR3 0x0003
+#define RL_IDR4 0x0004
+#define RL_IDR5 0x0005
/* 0006-0007 reserved */
-#define RL_MAR0 0x0008 /* Multicast hash table */
-#define RL_MAR1 0x0009
-#define RL_MAR2 0x000A
-#define RL_MAR3 0x000B
-#define RL_MAR4 0x000C
-#define RL_MAR5 0x000D
-#define RL_MAR6 0x000E
-#define RL_MAR7 0x000F
-
-#define RL_TXSTAT0 0x0010 /* status of TX descriptor 0 */
-#define RL_TXSTAT1 0x0014 /* status of TX descriptor 1 */
-#define RL_TXSTAT2 0x0018 /* status of TX descriptor 2 */
-#define RL_TXSTAT3 0x001C /* status of TX descriptor 3 */
-
-#define RL_TXADDR0 0x0020 /* address of TX descriptor 0 */
-#define RL_TXADDR1 0x0024 /* address of TX descriptor 1 */
-#define RL_TXADDR2 0x0028 /* address of TX descriptor 2 */
-#define RL_TXADDR3 0x002C /* address of TX descriptor 3 */
-
-#define RL_RXADDR 0x0030 /* RX ring start address */
-#define RL_RX_EARLY_BYTES 0x0034 /* RX early byte count */
-#define RL_RX_EARLY_STAT 0x0036 /* RX early status */
-#define RL_COMMAND 0x0037 /* command register */
-#define RL_CURRXADDR 0x0038 /* current address of packet read */
-#define RL_CURRXBUF 0x003A /* current RX buffer address */
-#define RL_IMR 0x003C /* interrupt mask register */
-#define RL_ISR 0x003E /* interrupt status register */
-#define RL_TXCFG 0x0040 /* transmit config */
-#define RL_RXCFG 0x0044 /* receive config */
-#define RL_TIMERCNT 0x0048 /* timer count register */
-#define RL_MISSEDPKT 0x004C /* missed packet counter */
-#define RL_EECMD 0x0050 /* EEPROM command register */
-#define RL_CFG0 0x0051 /* config register #0 */
-#define RL_CFG1 0x0052 /* config register #1 */
+#define RL_MAR0 0x0008 /* Multicast hash table */
+#define RL_MAR1 0x0009
+#define RL_MAR2 0x000A
+#define RL_MAR3 0x000B
+#define RL_MAR4 0x000C
+#define RL_MAR5 0x000D
+#define RL_MAR6 0x000E
+#define RL_MAR7 0x000F
+
+#define RL_TXSTAT0 0x0010 /* status of TX descriptor 0 */
+#define RL_TXSTAT1 0x0014 /* status of TX descriptor 1 */
+#define RL_TXSTAT2 0x0018 /* status of TX descriptor 2 */
+#define RL_TXSTAT3 0x001C /* status of TX descriptor 3 */
+
+#define RL_TXADDR0 0x0020 /* address of TX descriptor 0 */
+#define RL_TXADDR1 0x0024 /* address of TX descriptor 1 */
+#define RL_TXADDR2 0x0028 /* address of TX descriptor 2 */
+#define RL_TXADDR3 0x002C /* address of TX descriptor 3 */
+
+#define RL_RXADDR 0x0030 /* RX ring start address */
+#define RL_RX_EARLY_BYTES 0x0034 /* RX early byte count */
+#define RL_RX_EARLY_STAT 0x0036 /* RX early status */
+#define RL_COMMAND 0x0037 /* command register */
+#define RL_CURRXADDR 0x0038 /* current address of packet read */
+#define RL_CURRXBUF 0x003A /* current RX buffer address */
+#define RL_IMR 0x003C /* interrupt mask register */
+#define RL_ISR 0x003E /* interrupt status register */
+#define RL_TXCFG 0x0040 /* transmit config */
+#define RL_RXCFG 0x0044 /* receive config */
+#define RL_TIMERCNT 0x0048 /* timer count register */
+#define RL_MISSEDPKT 0x004C /* missed packet counter */
+#define RL_EECMD 0x0050 /* EEPROM command register */
+#define RL_CFG0 0x0051 /* config register #0 */
+#define RL_CFG1 0x0052 /* config register #1 */
#define RL_CFG2 0x0053 /* config register #2 */
#define RL_CFG3 0x0054 /* config register #3 */
#define RL_CFG4 0x0055 /* config register #4 */
#define RL_CFG5 0x0056 /* config register #5 */
/* 0057 reserved */
-#define RL_MEDIASTAT 0x0058 /* media status register (8139) */
+#define RL_MEDIASTAT 0x0058 /* media status register (8139) */
/* 0059-005A reserved */
-#define RL_MII 0x005A /* 8129 chip only */
-#define RL_HALTCLK 0x005B
-#define RL_MULTIINTR 0x005C /* multiple interrupt */
-#define RL_PCIREV 0x005E /* PCI revision value */
+#define RL_MII 0x005A /* 8129 chip only */
+#define RL_HALTCLK 0x005B
+#define RL_MULTIINTR 0x005C /* multiple interrupt */
+#define RL_PCIREV 0x005E /* PCI revision value */
/* 005F reserved */
-#define RL_TXSTAT_ALL 0x0060 /* TX status of all descriptors */
+#define RL_TXSTAT_ALL 0x0060 /* TX status of all descriptors */
/* Direct PHY access registers only available on 8139 */
-#define RL_BMCR 0x0062 /* PHY basic mode control */
-#define RL_BMSR 0x0064 /* PHY basic mode status */
-#define RL_ANAR 0x0066 /* PHY autoneg advert */
-#define RL_LPAR 0x0068 /* PHY link partner ability */
-#define RL_ANER 0x006A /* PHY autoneg expansion */
+#define RL_BMCR 0x0062 /* PHY basic mode control */
+#define RL_BMSR 0x0064 /* PHY basic mode status */
+#define RL_ANAR 0x0066 /* PHY autoneg advert */
+#define RL_LPAR 0x0068 /* PHY link partner ability */
+#define RL_ANER 0x006A /* PHY autoneg expansion */
-#define RL_DISCCNT 0x006C /* disconnect counter */
-#define RL_FALSECAR 0x006E /* false carrier counter */
-#define RL_NWAYTST 0x0070 /* NWAY test register */
-#define RL_RX_ER 0x0072 /* RX_ER counter */
-#define RL_CSCFG 0x0074 /* CS configuration register */
+#define RL_DISCCNT 0x006C /* disconnect counter */
+#define RL_FALSECAR 0x006E /* false carrier counter */
+#define RL_NWAYTST 0x0070 /* NWAY test register */
+#define RL_RX_ER 0x0072 /* RX_ER counter */
+#define RL_CSCFG 0x0074 /* CS configuration register */
/*
* When operating in special C+ mode, some of the registers in an
* 8139C+ chip have different definitions. These are also used for
* the 8169 gigE chip.
*/
-#define RL_DUMPSTATS_LO 0x0010 /* counter dump command register */
-#define RL_DUMPSTATS_HI 0x0014 /* counter dump command register */
-#define RL_TXLIST_ADDR_LO 0x0020 /* 64 bits, 256 byte alignment */
-#define RL_TXLIST_ADDR_HI 0x0024 /* 64 bits, 256 byte alignment */
-#define RL_TXLIST_ADDR_HPRIO_LO 0x0028 /* 64 bits, 256 byte alignment */
-#define RL_TXLIST_ADDR_HPRIO_HI 0x002C /* 64 bits, 256 byte alignment */
-#define RL_CFG2 0x0053
-#define RL_TIMERINT 0x0054 /* interrupt on timer expire */
-#define RL_TXSTART 0x00D9 /* 8 bits */
-#define RL_CPLUS_CMD 0x00E0 /* 16 bits */
-#define RL_RXLIST_ADDR_LO 0x00E4 /* 64 bits, 256 byte alignment */
-#define RL_RXLIST_ADDR_HI 0x00E8 /* 64 bits, 256 byte alignment */
-#define RL_EARLY_TX_THRESH 0x00EC /* 8 bits */
+#define RL_DUMPSTATS_LO 0x0010 /* counter dump command register */
+#define RL_DUMPSTATS_HI 0x0014 /* counter dump command register */
+#define RL_TXLIST_ADDR_LO 0x0020 /* 64 bits, 256 byte alignment */
+#define RL_TXLIST_ADDR_HI 0x0024 /* 64 bits, 256 byte alignment */
+#define RL_TXLIST_ADDR_HPRIO_LO 0x0028 /* 64 bits, 256 byte alignment */
+#define RL_TXLIST_ADDR_HPRIO_HI 0x002C /* 64 bits, 256 byte alignment */
+#define RL_CFG2 0x0053
+#define RL_TIMERINT 0x0054 /* interrupt on timer expire */
+#define RL_TXSTART 0x00D9 /* 8 bits */
+#define RL_CPLUS_CMD 0x00E0 /* 16 bits */
+#define RL_RXLIST_ADDR_LO 0x00E4 /* 64 bits, 256 byte alignment */
+#define RL_RXLIST_ADDR_HI 0x00E8 /* 64 bits, 256 byte alignment */
+#define RL_EARLY_TX_THRESH 0x00EC /* 8 bits */
/*
* Registers specific to the 8169 gigE chip
*/
-#define RL_TIMERINT_8169 0x0058 /* different offset than 8139 */
-#define RL_PHYAR 0x0060
-#define RL_TBICSR 0x0064
-#define RL_TBI_ANAR 0x0068
-#define RL_TBI_LPAR 0x006A
-#define RL_GMEDIASTAT 0x006C /* 8 bits */
-#define RL_MACDBG 0x006D /* 8 bits, 8168C SPIN2 only */
-#define RL_GPIO 0x006E /* 8 bits, 8168C SPIN2 only */
-#define RL_PMCH 0x006F /* 8 bits */
-#define RL_MAXRXPKTLEN 0x00DA /* 16 bits, chip multiplies by 8 */
-#define RL_GTXSTART 0x0038 /* 8 bits */
+#define RL_GTXSTART 0x0038 /* 8 bits */
+#define RL_TIMERINT_8169 0x0058 /* different offset than 8139 */
+#define RL_PHYAR 0x0060
+#define RL_TBICSR 0x0064
+#define RL_TBI_ANAR 0x0068
+#define RL_TBI_LPAR 0x006A
+#define RL_GMEDIASTAT 0x006C /* 8 bits */
+#define RL_MACDBG 0x006D /* 8 bits, 8168C SPIN2 only */
+#define RL_GPIO 0x006E /* 8 bits, 8168C SPIN2 only */
+#define RL_PMCH 0x006F /* 8 bits */
+#define RL_MAXRXPKTLEN 0x00DA /* 16 bits, chip multiplies by 8 */
+#define RL_INTRMOD 0x00E2 /* 16 bits */
/*
* TX config register bits
*/
-#define RL_TXCFG_CLRABRT 0x00000001 /* retransmit aborted pkt */
-#define RL_TXCFG_MAXDMA 0x00000700 /* max DMA burst size */
-#define RL_TXCFG_CRCAPPEND 0x00010000 /* CRC append (0 = yes) */
-#define RL_TXCFG_LOOPBKTST 0x00060000 /* loopback test */
-#define RL_TXCFG_IFG2 0x00080000 /* 8169 only */
-#define RL_TXCFG_IFG 0x03000000 /* interframe gap */
-#define RL_TXCFG_HWREV 0x7CC00000
+#define RL_TXCFG_CLRABRT 0x00000001 /* retransmit aborted pkt */
+#define RL_TXCFG_MAXDMA 0x00000700 /* max DMA burst size */
+#define RL_TXCFG_CRCAPPEND 0x00010000 /* CRC append (0 = yes) */
+#define RL_TXCFG_LOOPBKTST 0x00060000 /* loopback test */
+#define RL_TXCFG_IFG2 0x00080000 /* 8169 only */
+#define RL_TXCFG_IFG 0x03000000 /* interframe gap */
+#define RL_TXCFG_HWREV 0x7CC00000
-#define RL_LOOPTEST_OFF 0x00000000
-#define RL_LOOPTEST_ON 0x00020000
-#define RL_LOOPTEST_ON_CPLUS 0x00060000
+#define RL_LOOPTEST_OFF 0x00000000
+#define RL_LOOPTEST_ON 0x00020000
+#define RL_LOOPTEST_ON_CPLUS 0x00060000
/* Known revision codes. */
-#define RL_HWREV_8169 0x00000000
-#define RL_HWREV_8169S 0x00800000
-#define RL_HWREV_8110S 0x04000000
-#define RL_HWREV_8169_8110SB 0x10000000
-#define RL_HWREV_8169_8110SC 0x18000000
-#define RL_HWREV_8102EL 0x24800000
-#define RL_HWREV_8102EL_SPIN1 0x24C00000
-#define RL_HWREV_8168D 0x28000000
-#define RL_HWREV_8168DP 0x28800000
-#define RL_HWREV_8168E 0x2C000000
-#define RL_HWREV_8168_SPIN1 0x30000000
-#define RL_HWREV_8100E 0x30800000
-#define RL_HWREV_8101E 0x34000000
-#define RL_HWREV_8102E 0x34800000
-#define RL_HWREV_8103E 0x34C00000
-#define RL_HWREV_8168_SPIN2 0x38000000
-#define RL_HWREV_8168_SPIN3 0x38400000
-#define RL_HWREV_8168C 0x3C000000
-#define RL_HWREV_8168C_SPIN2 0x3C400000
-#define RL_HWREV_8168CP 0x3C800000
-#define RL_HWREV_8139 0x60000000
-#define RL_HWREV_8139A 0x70000000
-#define RL_HWREV_8139AG 0x70800000
-#define RL_HWREV_8139B 0x78000000
-#define RL_HWREV_8130 0x7C000000
-#define RL_HWREV_8139C 0x74000000
-#define RL_HWREV_8139D 0x74400000
-#define RL_HWREV_8139CPLUS 0x74800000
-#define RL_HWREV_8101 0x74C00000
-#define RL_HWREV_8100 0x78800000
-#define RL_HWREV_8169_8110SBL 0x7CC00000
-#define RL_HWREV_8169_8110SCE 0x98000000
-
-#define RL_TXDMA_16BYTES 0x00000000
-#define RL_TXDMA_32BYTES 0x00000100
-#define RL_TXDMA_64BYTES 0x00000200
-#define RL_TXDMA_128BYTES 0x00000300
-#define RL_TXDMA_256BYTES 0x00000400
-#define RL_TXDMA_512BYTES 0x00000500
-#define RL_TXDMA_1024BYTES 0x00000600
-#define RL_TXDMA_2048BYTES 0x00000700
+#define RL_HWREV_8169 0x00000000
+#define RL_HWREV_8169S 0x00800000
+#define RL_HWREV_8110S 0x04000000
+#define RL_HWREV_8169_8110SB 0x10000000
+#define RL_HWREV_8169_8110SC 0x18000000
+#define RL_HWREV_8102EL 0x24800000
+#define RL_HWREV_8102EL_SPIN1 0x24C00000
+#define RL_HWREV_8168D 0x28000000
+#define RL_HWREV_8168DP 0x28800000
+#define RL_HWREV_8168E 0x2C000000
+#define RL_HWREV_8168_SPIN1 0x30000000
+#define RL_HWREV_8100E 0x30800000
+#define RL_HWREV_8101E 0x34000000
+#define RL_HWREV_8102E 0x34800000
+#define RL_HWREV_8103E 0x34C00000
+#define RL_HWREV_8168_SPIN2 0x38000000
+#define RL_HWREV_8168_SPIN3 0x38400000
+#define RL_HWREV_8168C 0x3C000000
+#define RL_HWREV_8168C_SPIN2 0x3C400000
+#define RL_HWREV_8168CP 0x3C800000
+#define RL_HWREV_8139 0x60000000
+#define RL_HWREV_8139A 0x70000000
+#define RL_HWREV_8139AG 0x70800000
+#define RL_HWREV_8139B 0x78000000
+#define RL_HWREV_8130 0x7C000000
+#define RL_HWREV_8139C 0x74000000
+#define RL_HWREV_8139D 0x74400000
+#define RL_HWREV_8139CPLUS 0x74800000
+#define RL_HWREV_8101 0x74C00000
+#define RL_HWREV_8100 0x78800000
+#define RL_HWREV_8169_8110SBL 0x7CC00000
+#define RL_HWREV_8169_8110SCE 0x98000000
+
+#define RL_TXDMA_16BYTES 0x00000000
+#define RL_TXDMA_32BYTES 0x00000100
+#define RL_TXDMA_64BYTES 0x00000200
+#define RL_TXDMA_128BYTES 0x00000300
+#define RL_TXDMA_256BYTES 0x00000400
+#define RL_TXDMA_512BYTES 0x00000500
+#define RL_TXDMA_1024BYTES 0x00000600
+#define RL_TXDMA_2048BYTES 0x00000700
/*
* Transmit descriptor status register bits.
*/
-#define RL_TXSTAT_LENMASK 0x00001FFF
-#define RL_TXSTAT_OWN 0x00002000
-#define RL_TXSTAT_TX_UNDERRUN 0x00004000
-#define RL_TXSTAT_TX_OK 0x00008000
-#define RL_TXSTAT_EARLY_THRESH 0x003F0000
-#define RL_TXSTAT_COLLCNT 0x0F000000
-#define RL_TXSTAT_CARR_HBEAT 0x10000000
-#define RL_TXSTAT_OUTOFWIN 0x20000000
-#define RL_TXSTAT_TXABRT 0x40000000
-#define RL_TXSTAT_CARRLOSS 0x80000000
+#define RL_TXSTAT_LENMASK 0x00001FFF
+#define RL_TXSTAT_OWN 0x00002000
+#define RL_TXSTAT_TX_UNDERRUN 0x00004000
+#define RL_TXSTAT_TX_OK 0x00008000
+#define RL_TXSTAT_EARLY_THRESH 0x003F0000
+#define RL_TXSTAT_COLLCNT 0x0F000000
+#define RL_TXSTAT_CARR_HBEAT 0x10000000
+#define RL_TXSTAT_OUTOFWIN 0x20000000
+#define RL_TXSTAT_TXABRT 0x40000000
+#define RL_TXSTAT_CARRLOSS 0x80000000
/*
* Interrupt status register bits.
*/
-#define RL_ISR_RX_OK 0x0001
-#define RL_ISR_RX_ERR 0x0002
-#define RL_ISR_TX_OK 0x0004
-#define RL_ISR_TX_ERR 0x0008
-#define RL_ISR_RX_OVERRUN 0x0010
-#define RL_ISR_PKT_UNDERRUN 0x0020
-#define RL_ISR_LINKCHG 0x0020 /* 8169 only */
-#define RL_ISR_FIFO_OFLOW 0x0040 /* 8139 only */
-#define RL_ISR_TX_DESC_UNAVAIL 0x0080 /* C+ only */
-#define RL_ISR_SWI 0x0100 /* C+ only */
-#define RL_ISR_CABLE_LEN_CHGD 0x2000
-#define RL_ISR_PCS_TIMEOUT 0x4000 /* 8129 only */
-#define RL_ISR_TIMEOUT_EXPIRED 0x4000
-#define RL_ISR_SYSTEM_ERR 0x8000
-
-#define RL_INTRS \
+#define RL_ISR_RX_OK 0x0001
+#define RL_ISR_RX_ERR 0x0002
+#define RL_ISR_TX_OK 0x0004
+#define RL_ISR_TX_ERR 0x0008
+#define RL_ISR_RX_OVERRUN 0x0010
+#define RL_ISR_PKT_UNDERRUN 0x0020
+#define RL_ISR_LINKCHG 0x0020 /* 8169 only */
+#define RL_ISR_FIFO_OFLOW 0x0040 /* 8139 only */
+#define RL_ISR_TX_DESC_UNAVAIL 0x0080 /* C+ only */
+#define RL_ISR_SWI 0x0100 /* C+ only */
+#define RL_ISR_CABLE_LEN_CHGD 0x2000
+#define RL_ISR_PCS_TIMEOUT 0x4000 /* 8129 only */
+#define RL_ISR_TIMEOUT_EXPIRED 0x4000
+#define RL_ISR_SYSTEM_ERR 0x8000
+
+#define RL_INTRS \
(RL_ISR_TX_OK|RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \
RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \
RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR)
#ifdef RE_TX_MODERATION
-#define RL_INTRS_CPLUS \
+#define RL_INTRS_CPLUS \
(RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \
RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \
RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED)
#else
-#define RL_INTRS_CPLUS \
+#define RL_INTRS_CPLUS \
(RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR|RL_ISR_TX_OK| \
RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \
RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED)
@@ -248,169 +249,169 @@
/*
* Media status register. (8139 only)
*/
-#define RL_MEDIASTAT_RXPAUSE 0x01
-#define RL_MEDIASTAT_TXPAUSE 0x02
-#define RL_MEDIASTAT_LINK 0x04
-#define RL_MEDIASTAT_SPEED10 0x08
-#define RL_MEDIASTAT_RXFLOWCTL 0x40 /* duplex mode */
-#define RL_MEDIASTAT_TXFLOWCTL 0x80 /* duplex mode */
+#define RL_MEDIASTAT_RXPAUSE 0x01
+#define RL_MEDIASTAT_TXPAUSE 0x02
+#define RL_MEDIASTAT_LINK 0x04
+#define RL_MEDIASTAT_SPEED10 0x08
+#define RL_MEDIASTAT_RXFLOWCTL 0x40 /* duplex mode */
+#define RL_MEDIASTAT_TXFLOWCTL 0x80 /* duplex mode */
/*
* Receive config register.
*/
-#define RL_RXCFG_RX_ALLPHYS 0x00000001 /* accept all nodes */
-#define RL_RXCFG_RX_INDIV 0x00000002 /* match filter */
-#define RL_RXCFG_RX_MULTI 0x00000004 /* accept all multicast */
-#define RL_RXCFG_RX_BROAD 0x00000008 /* accept all broadcast */
-#define RL_RXCFG_RX_RUNT 0x00000010
-#define RL_RXCFG_RX_ERRPKT 0x00000020
-#define RL_RXCFG_WRAP 0x00000080
-#define RL_RXCFG_MAXDMA 0x00000700
-#define RL_RXCFG_BUFSZ 0x00001800
-#define RL_RXCFG_FIFOTHRESH 0x0000E000
-#define RL_RXCFG_EARLYTHRESH 0x07000000
-
-#define RL_RXDMA_16BYTES 0x00000000
-#define RL_RXDMA_32BYTES 0x00000100
-#define RL_RXDMA_64BYTES 0x00000200
-#define RL_RXDMA_128BYTES 0x00000300
-#define RL_RXDMA_256BYTES 0x00000400
-#define RL_RXDMA_512BYTES 0x00000500
-#define RL_RXDMA_1024BYTES 0x00000600
-#define RL_RXDMA_UNLIMITED 0x00000700
-
-#define RL_RXBUF_8 0x00000000
-#define RL_RXBUF_16 0x00000800
-#define RL_RXBUF_32 0x00001000
-#define RL_RXBUF_64 0x00001800
-
-#define RL_RXFIFO_16BYTES 0x00000000
-#define RL_RXFIFO_32BYTES 0x00002000
-#define RL_RXFIFO_64BYTES 0x00004000
-#define RL_RXFIFO_128BYTES 0x00006000
-#define RL_RXFIFO_256BYTES 0x00008000
-#define RL_RXFIFO_512BYTES 0x0000A000
-#define RL_RXFIFO_1024BYTES 0x0000C000
-#define RL_RXFIFO_NOTHRESH 0x0000E000
+#define RL_RXCFG_RX_ALLPHYS 0x00000001 /* accept all nodes */
+#define RL_RXCFG_RX_INDIV 0x00000002 /* match filter */
+#define RL_RXCFG_RX_MULTI 0x00000004 /* accept all multicast */
+#define RL_RXCFG_RX_BROAD 0x00000008 /* accept all broadcast */
+#define RL_RXCFG_RX_RUNT 0x00000010
+#define RL_RXCFG_RX_ERRPKT 0x00000020
+#define RL_RXCFG_WRAP 0x00000080
+#define RL_RXCFG_MAXDMA 0x00000700
+#define RL_RXCFG_BUFSZ 0x00001800
+#define RL_RXCFG_FIFOTHRESH 0x0000E000
+#define RL_RXCFG_EARLYTHRESH 0x07000000
+
+#define RL_RXDMA_16BYTES 0x00000000
+#define RL_RXDMA_32BYTES 0x00000100
+#define RL_RXDMA_64BYTES 0x00000200
+#define RL_RXDMA_128BYTES 0x00000300
+#define RL_RXDMA_256BYTES 0x00000400
+#define RL_RXDMA_512BYTES 0x00000500
+#define RL_RXDMA_1024BYTES 0x00000600
+#define RL_RXDMA_UNLIMITED 0x00000700
+
+#define RL_RXBUF_8 0x00000000
+#define RL_RXBUF_16 0x00000800
+#define RL_RXBUF_32 0x00001000
+#define RL_RXBUF_64 0x00001800
+
+#define RL_RXFIFO_16BYTES 0x00000000
+#define RL_RXFIFO_32BYTES 0x00002000
+#define RL_RXFIFO_64BYTES 0x00004000
+#define RL_RXFIFO_128BYTES 0x00006000
+#define RL_RXFIFO_256BYTES 0x00008000
+#define RL_RXFIFO_512BYTES 0x0000A000
+#define RL_RXFIFO_1024BYTES 0x0000C000
+#define RL_RXFIFO_NOTHRESH 0x0000E000
/*
* Bits in RX status header (included with RX'ed packet
* in ring buffer).
*/
-#define RL_RXSTAT_RXOK 0x00000001
-#define RL_RXSTAT_ALIGNERR 0x00000002
-#define RL_RXSTAT_CRCERR 0x00000004
-#define RL_RXSTAT_GIANT 0x00000008
-#define RL_RXSTAT_RUNT 0x00000010
-#define RL_RXSTAT_BADSYM 0x00000020
-#define RL_RXSTAT_BROAD 0x00002000
-#define RL_RXSTAT_INDIV 0x00004000
-#define RL_RXSTAT_MULTI 0x00008000
-#define RL_RXSTAT_LENMASK 0xFFFF0000
+#define RL_RXSTAT_RXOK 0x00000001
+#define RL_RXSTAT_ALIGNERR 0x00000002
+#define RL_RXSTAT_CRCERR 0x00000004
+#define RL_RXSTAT_GIANT 0x00000008
+#define RL_RXSTAT_RUNT 0x00000010
+#define RL_RXSTAT_BADSYM 0x00000020
+#define RL_RXSTAT_BROAD 0x00002000
+#define RL_RXSTAT_INDIV 0x00004000
+#define RL_RXSTAT_MULTI 0x00008000
+#define RL_RXSTAT_LENMASK 0xFFFF0000
-#define RL_RXSTAT_UNFINISHED 0xFFF0 /* DMA still in progress */
+#define RL_RXSTAT_UNFINISHED 0xFFF0 /* DMA still in progress */
/*
* Command register.
*/
-#define RL_CMD_EMPTY_RXBUF 0x0001
-#define RL_CMD_TX_ENB 0x0004
-#define RL_CMD_RX_ENB 0x0008
-#define RL_CMD_RESET 0x0010
-#define RL_CMD_STOPREQ 0x0080
+#define RL_CMD_EMPTY_RXBUF 0x0001
+#define RL_CMD_TX_ENB 0x0004
+#define RL_CMD_RX_ENB 0x0008
+#define RL_CMD_RESET 0x0010
+#define RL_CMD_STOPREQ 0x0080
/*
* Twister register values. These are completely undocumented and derived
* from public sources.
*/
-#define RL_CSCFG_LINK_OK 0x0400
-#define RL_CSCFG_CHANGE 0x0800
-#define RL_CSCFG_STATUS 0xf000
-#define RL_CSCFG_ROW3 0x7000
-#define RL_CSCFG_ROW2 0x3000
-#define RL_CSCFG_ROW1 0x1000
-#define RL_CSCFG_LINK_DOWN_OFF_CMD 0x03c0
-#define RL_CSCFG_LINK_DOWN_CMD 0xf3c0
+#define RL_CSCFG_LINK_OK 0x0400
+#define RL_CSCFG_CHANGE 0x0800
+#define RL_CSCFG_STATUS 0xf000
+#define RL_CSCFG_ROW3 0x7000
+#define RL_CSCFG_ROW2 0x3000
+#define RL_CSCFG_ROW1 0x1000
+#define RL_CSCFG_LINK_DOWN_OFF_CMD 0x03c0
+#define RL_CSCFG_LINK_DOWN_CMD 0xf3c0
-#define RL_NWAYTST_RESET 0
-#define RL_NWAYTST_CBL_TEST 0x20
+#define RL_NWAYTST_RESET 0
+#define RL_NWAYTST_CBL_TEST 0x20
-#define RL_PARA78 0x78
-#define RL_PARA78_DEF 0x78fa8388
-#define RL_PARA7C 0x7C
-#define RL_PARA7C_DEF 0xcb38de43
-#define RL_PARA7C_RETUNE 0xfb38de03
+#define RL_PARA78 0x78
+#define RL_PARA78_DEF 0x78fa8388
+#define RL_PARA7C 0x7C
+#define RL_PARA7C_DEF 0xcb38de43
+#define RL_PARA7C_RETUNE 0xfb38de03
/*
* EEPROM control register
*/
-#define RL_EE_DATAOUT 0x01 /* Data out */
-#define RL_EE_DATAIN 0x02 /* Data in */
-#define RL_EE_CLK 0x04 /* clock */
-#define RL_EE_SEL 0x08 /* chip select */
-#define RL_EE_MODE (0x40|0x80)
+#define RL_EE_DATAOUT 0x01 /* Data out */
+#define RL_EE_DATAIN 0x02 /* Data in */
+#define RL_EE_CLK 0x04 /* clock */
+#define RL_EE_SEL 0x08 /* chip select */
+#define RL_EE_MODE (0x40|0x80)
-#define RL_EEMODE_OFF 0x00
-#define RL_EEMODE_AUTOLOAD 0x40
-#define RL_EEMODE_PROGRAM 0x80
-#define RL_EEMODE_WRITECFG (0x80|0x40)
+#define RL_EEMODE_OFF 0x00
+#define RL_EEMODE_AUTOLOAD 0x40
+#define RL_EEMODE_PROGRAM 0x80
+#define RL_EEMODE_WRITECFG (0x80|0x40)
/* 9346 EEPROM commands */
-#define RL_9346_ADDR_LEN 6 /* 93C46 1K: 128x16 */
-#define RL_9356_ADDR_LEN 8 /* 93C56 2K: 256x16 */
-
-#define RL_9346_WRITE 0x5
-#define RL_9346_READ 0x6
-#define RL_9346_ERASE 0x7
-#define RL_9346_EWEN 0x4
-#define RL_9346_EWEN_ADDR 0x30
-#define RL_9456_EWDS 0x4
-#define RL_9346_EWDS_ADDR 0x00
-
-#define RL_EECMD_WRITE 0x140
-#define RL_EECMD_READ_6BIT 0x180
-#define RL_EECMD_READ_8BIT 0x600
-#define RL_EECMD_ERASE 0x1c0
-
-#define RL_EE_ID 0x00
-#define RL_EE_PCI_VID 0x01
-#define RL_EE_PCI_DID 0x02
+#define RL_9346_ADDR_LEN 6 /* 93C46 1K: 128x16 */
+#define RL_9356_ADDR_LEN 8 /* 93C56 2K: 256x16 */
+
+#define RL_9346_WRITE 0x5
+#define RL_9346_READ 0x6
+#define RL_9346_ERASE 0x7
+#define RL_9346_EWEN 0x4
+#define RL_9346_EWEN_ADDR 0x30
+#define RL_9456_EWDS 0x4
+#define RL_9346_EWDS_ADDR 0x00
+
+#define RL_EECMD_WRITE 0x140
+#define RL_EECMD_READ_6BIT 0x180
+#define RL_EECMD_READ_8BIT 0x600
+#define RL_EECMD_ERASE 0x1c0
+
+#define RL_EE_ID 0x00
+#define RL_EE_PCI_VID 0x01
+#define RL_EE_PCI_DID 0x02
/* Location of station address inside EEPROM */
-#define RL_EE_EADDR 0x07
+#define RL_EE_EADDR 0x07
/*
* MII register (8129 only)
*/
-#define RL_MII_CLK 0x01
-#define RL_MII_DATAIN 0x02
-#define RL_MII_DATAOUT 0x04
-#define RL_MII_DIR 0x80 /* 0 == input, 1 == output */
+#define RL_MII_CLK 0x01
+#define RL_MII_DATAIN 0x02
+#define RL_MII_DATAOUT 0x04
+#define RL_MII_DIR 0x80 /* 0 == input, 1 == output */
/*
* Config 0 register
*/
-#define RL_CFG0_ROM0 0x01
-#define RL_CFG0_ROM1 0x02
-#define RL_CFG0_ROM2 0x04
-#define RL_CFG0_PL0 0x08
-#define RL_CFG0_PL1 0x10
-#define RL_CFG0_10MBPS 0x20 /* 10 Mbps internal mode */
-#define RL_CFG0_PCS 0x40
-#define RL_CFG0_SCR 0x80
+#define RL_CFG0_ROM0 0x01
+#define RL_CFG0_ROM1 0x02
+#define RL_CFG0_ROM2 0x04
+#define RL_CFG0_PL0 0x08
+#define RL_CFG0_PL1 0x10
+#define RL_CFG0_10MBPS 0x20 /* 10 Mbps internal mode */
+#define RL_CFG0_PCS 0x40
+#define RL_CFG0_SCR 0x80
/*
* Config 1 register
*/
-#define RL_CFG1_PWRDWN 0x01
-#define RL_CFG1_PME 0x01
-#define RL_CFG1_SLEEP 0x02
-#define RL_CFG1_VPDEN 0x02
-#define RL_CFG1_IOMAP 0x04
-#define RL_CFG1_MEMMAP 0x08
-#define RL_CFG1_RSVD 0x10
+#define RL_CFG1_PWRDWN 0x01
+#define RL_CFG1_PME 0x01
+#define RL_CFG1_SLEEP 0x02
+#define RL_CFG1_VPDEN 0x02
+#define RL_CFG1_IOMAP 0x04
+#define RL_CFG1_MEMMAP 0x08
+#define RL_CFG1_RSVD 0x10
#define RL_CFG1_LWACT 0x10
-#define RL_CFG1_DRVLOAD 0x20
-#define RL_CFG1_LED0 0x40
-#define RL_CFG1_FULLDUPLEX 0x40 /* 8129 only */
-#define RL_CFG1_LED1 0x80
+#define RL_CFG1_DRVLOAD 0x20
+#define RL_CFG1_LED0 0x40
+#define RL_CFG1_FULLDUPLEX 0x40 /* 8129 only */
+#define RL_CFG1_LED1 0x80
/*
* Config 2 register
@@ -450,35 +451,35 @@
/* RL_DUMPSTATS_LO register */
-#define RL_DUMPSTATS_START 0x00000008
+#define RL_DUMPSTATS_START 0x00000008
/* Transmit start register */
-#define RL_TXSTART_SWI 0x01 /* generate TX interrupt */
-#define RL_TXSTART_START 0x40 /* start normal queue transmit */
-#define RL_TXSTART_HPRIO_START 0x80 /* start hi prio queue transmit */
+#define RL_TXSTART_SWI 0x01 /* generate TX interrupt */
+#define RL_TXSTART_START 0x40 /* start normal queue transmit */
+#define RL_TXSTART_HPRIO_START 0x80 /* start hi prio queue transmit */
/*
* Config 2 register, 8139C+/8169/8169S/8110S only
*/
-#define RL_CFG2_BUSFREQ 0x07
-#define RL_CFG2_BUSWIDTH 0x08
-#define RL_CFG2_AUXPWRSTS 0x10
+#define RL_CFG2_BUSFREQ 0x07
+#define RL_CFG2_BUSWIDTH 0x08
+#define RL_CFG2_AUXPWRSTS 0x10
-#define RL_BUSFREQ_33MHZ 0x00
-#define RL_BUSFREQ_66MHZ 0x01
-
-#define RL_BUSWIDTH_32BITS 0x00
-#define RL_BUSWIDTH_64BITS 0x08
+#define RL_BUSFREQ_33MHZ 0x00
+#define RL_BUSFREQ_66MHZ 0x01
+
+#define RL_BUSWIDTH_32BITS 0x00
+#define RL_BUSWIDTH_64BITS 0x08
/* C+ mode command register */
-#define RL_CPLUSCMD_TXENB 0x0001 /* enable C+ transmit mode */
-#define RL_CPLUSCMD_RXENB 0x0002 /* enable C+ receive mode */
-#define RL_CPLUSCMD_PCI_MRW 0x0008 /* enable PCI multi-read/write */
-#define RL_CPLUSCMD_PCI_DAC 0x0010 /* PCI dual-address cycle only */
-#define RL_CPLUSCMD_RXCSUM_ENB 0x0020 /* enable RX checksum offload */
-#define RL_CPLUSCMD_VLANSTRIP 0x0040 /* enable VLAN tag stripping */
+#define RL_CPLUSCMD_TXENB 0x0001 /* enable C+ transmit mode */
+#define RL_CPLUSCMD_RXENB 0x0002 /* enable C+ receive mode */
+#define RL_CPLUSCMD_PCI_MRW 0x0008 /* enable PCI multi-read/write */
+#define RL_CPLUSCMD_PCI_DAC 0x0010 /* PCI dual-address cycle only */
+#define RL_CPLUSCMD_RXCSUM_ENB 0x0020 /* enable RX checksum offload */
+#define RL_CPLUSCMD_VLANSTRIP 0x0040 /* enable VLAN tag stripping */
#define RL_CPLUSCMD_MACSTAT_DIS 0x0080 /* 8168B/C/CP */
#define RL_CPLUSCMD_ASF 0x0100 /* 8168C/CP */
#define RL_CPLUSCMD_DBG_SEL 0x0200 /* 8168C/CP */
@@ -491,27 +492,27 @@
/* C+ early transmit threshold */
-#define RL_EARLYTXTHRESH_CNT 0x003F /* byte count times 8 */
+#define RL_EARLYTXTHRESH_CNT 0x003F /* byte count times 8 */
/*
* Gigabit PHY access register (8169 only)
*/
-#define RL_PHYAR_PHYDATA 0x0000FFFF
-#define RL_PHYAR_PHYREG 0x001F0000
-#define RL_PHYAR_BUSY 0x80000000
+#define RL_PHYAR_PHYDATA 0x0000FFFF
+#define RL_PHYAR_PHYREG 0x001F0000
+#define RL_PHYAR_BUSY 0x80000000
/*
* Gigabit media status (8169 only)
*/
-#define RL_GMEDIASTAT_FDX 0x01 /* full duplex */
-#define RL_GMEDIASTAT_LINK 0x02 /* link up */
-#define RL_GMEDIASTAT_10MBPS 0x04 /* 10mps link */
-#define RL_GMEDIASTAT_100MBPS 0x08 /* 100mbps link */
-#define RL_GMEDIASTAT_1000MBPS 0x10 /* gigE link */
-#define RL_GMEDIASTAT_RXFLOW 0x20 /* RX flow control on */
-#define RL_GMEDIASTAT_TXFLOW 0x40 /* TX flow control on */
-#define RL_GMEDIASTAT_TBI 0x80 /* TBI enabled */
+#define RL_GMEDIASTAT_FDX 0x01 /* full duplex */
+#define RL_GMEDIASTAT_LINK 0x02 /* link up */
+#define RL_GMEDIASTAT_10MBPS 0x04 /* 10mps link */
+#define RL_GMEDIASTAT_100MBPS 0x08 /* 100mbps link */
+#define RL_GMEDIASTAT_1000MBPS 0x10 /* gigE link */
+#define RL_GMEDIASTAT_RXFLOW 0x20 /* RX flow control on */
+#define RL_GMEDIASTAT_TXFLOW 0x40 /* TX flow control on */
+#define RL_GMEDIASTAT_TBI 0x80 /* TBI enabled */
/*
* The RealTek doesn't use a fragment-based descriptor mechanism.
@@ -528,25 +529,25 @@
* all received packets.
*/
-#define RL_RX_BUF_SZ RL_RXBUF_64
-#define RL_RXBUFLEN (1 << ((RL_RX_BUF_SZ >> 11) + 13))
-#define RL_TX_LIST_CNT 4
-#define RL_MIN_FRAMELEN 60
+#define RL_RX_BUF_SZ RL_RXBUF_64
+#define RL_RXBUFLEN (1 << ((RL_RX_BUF_SZ >> 11) + 13))
+#define RL_TX_LIST_CNT 4
+#define RL_MIN_FRAMELEN 60
#define RL_TX_8139_BUF_ALIGN 4
#define RL_RX_8139_BUF_ALIGN 8
#define RL_RX_8139_BUF_RESERVE sizeof(int64_t)
#define RL_RX_8139_BUF_GUARD_SZ \
- (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN + RL_RX_8139_BUF_RESERVE)
-#define RL_TXTHRESH(x) ((x) << 11)
-#define RL_TX_THRESH_INIT 96
-#define RL_RX_FIFOTHRESH RL_RXFIFO_NOTHRESH
-#define RL_RX_MAXDMA RL_RXDMA_UNLIMITED
-#define RL_TX_MAXDMA RL_TXDMA_2048BYTES
+ (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN + RL_RX_8139_BUF_RESERVE)
+#define RL_TXTHRESH(x) ((x) << 11)
+#define RL_TX_THRESH_INIT 96
+#define RL_RX_FIFOTHRESH RL_RXFIFO_NOTHRESH
+#define RL_RX_MAXDMA RL_RXDMA_UNLIMITED
+#define RL_TX_MAXDMA RL_TXDMA_2048BYTES
-#define RL_RXCFG_CONFIG (RL_RX_FIFOTHRESH|RL_RX_MAXDMA|RL_RX_BUF_SZ)
-#define RL_TXCFG_CONFIG (RL_TXCFG_IFG|RL_TX_MAXDMA)
+#define RL_RXCFG_CONFIG (RL_RX_FIFOTHRESH|RL_RX_MAXDMA|RL_RX_BUF_SZ)
+#define RL_TXCFG_CONFIG (RL_TXCFG_IFG|RL_TX_MAXDMA)
-#define RL_ETHER_ALIGN 2
+#define RL_ETHER_ALIGN 2
/*
* re(4) hardware ip4csum-tx could be mangled with 28 bytes or less IP packets.
@@ -569,15 +570,15 @@ struct rl_chain_data {
uint8_t cur_tx;
};
-#define RL_INC(x) (x = (x + 1) % RL_TX_LIST_CNT)
-#define RL_CUR_TXADDR(x) ((x->rl_cdata.cur_tx * 4) + RL_TXADDR0)
-#define RL_CUR_TXSTAT(x) ((x->rl_cdata.cur_tx * 4) + RL_TXSTAT0)
-#define RL_CUR_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.cur_tx])
-#define RL_CUR_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.cur_tx])
-#define RL_LAST_TXADDR(x) ((x->rl_cdata.last_tx * 4) + RL_TXADDR0)
-#define RL_LAST_TXSTAT(x) ((x->rl_cdata.last_tx * 4) + RL_TXSTAT0)
-#define RL_LAST_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.last_tx])
-#define RL_LAST_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.last_tx])
+#define RL_INC(x) (x = (x + 1) % RL_TX_LIST_CNT)
+#define RL_CUR_TXADDR(x) ((x->rl_cdata.cur_tx * 4) + RL_TXADDR0)
+#define RL_CUR_TXSTAT(x) ((x->rl_cdata.cur_tx * 4) + RL_TXSTAT0)
+#define RL_CUR_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.cur_tx])
+#define RL_CUR_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.cur_tx])
+#define RL_LAST_TXADDR(x) ((x->rl_cdata.last_tx * 4) + RL_TXADDR0)
+#define RL_LAST_TXSTAT(x) ((x->rl_cdata.last_tx * 4) + RL_TXSTAT0)
+#define RL_LAST_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.last_tx])
+#define RL_LAST_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.last_tx])
struct rl_type {
uint16_t rl_vid;
@@ -604,17 +605,17 @@ struct rl_mii_frame {
/*
* MII constants
*/
-#define RL_MII_STARTDELIM 0x01
-#define RL_MII_READOP 0x02
-#define RL_MII_WRITEOP 0x01
-#define RL_MII_TURNAROUND 0x02
+#define RL_MII_STARTDELIM 0x01
+#define RL_MII_READOP 0x02
+#define RL_MII_WRITEOP 0x01
+#define RL_MII_TURNAROUND 0x02
-#define RL_8129 1
-#define RL_8139 2
-#define RL_8139CPLUS 3
-#define RL_8169 4
+#define RL_8129 1
+#define RL_8139 2
+#define RL_8139CPLUS 3
+#define RL_8169 4
-#define RL_ISCPLUS(x) ((x)->rl_type == RL_8139CPLUS || \
+#define RL_ISCPLUS(x) ((x)->rl_type == RL_8139CPLUS || \
(x)->rl_type == RL_8169)
/*
@@ -638,85 +639,85 @@ struct rl_desc {
uint32_t rl_bufaddr_hi;
};
-#define RL_TDESC_CMD_FRAGLEN 0x0000FFFF
-#define RL_TDESC_CMD_TCPCSUM 0x00010000 /* TCP checksum enable */
-#define RL_TDESC_CMD_UDPCSUM 0x00020000 /* UDP checksum enable */
-#define RL_TDESC_CMD_IPCSUM 0x00040000 /* IP header checksum enable */
-#define RL_TDESC_CMD_MSSVAL 0x07FF0000 /* Large send MSS value */
-#define RL_TDESC_CMD_MSSVAL_SHIFT 16 /* Large send MSS value shift */
-#define RL_TDESC_CMD_LGSEND 0x08000000 /* TCP large send enb */
-#define RL_TDESC_CMD_EOF 0x10000000 /* end of frame marker */
-#define RL_TDESC_CMD_SOF 0x20000000 /* start of frame marker */
-#define RL_TDESC_CMD_EOR 0x40000000 /* end of ring marker */
-#define RL_TDESC_CMD_OWN 0x80000000 /* chip owns descriptor */
-
-#define RL_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */
-#define RL_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
+#define RL_TDESC_CMD_FRAGLEN 0x0000FFFF
+#define RL_TDESC_CMD_TCPCSUM 0x00010000 /* TCP checksum enable */
+#define RL_TDESC_CMD_UDPCSUM 0x00020000 /* UDP checksum enable */
+#define RL_TDESC_CMD_IPCSUM 0x00040000 /* IP header checksum enable */
+#define RL_TDESC_CMD_MSSVAL 0x07FF0000 /* Large send MSS value */
+#define RL_TDESC_CMD_MSSVAL_SHIFT 16 /* Large send MSS value shift */
+#define RL_TDESC_CMD_LGSEND 0x08000000 /* TCP large send enb */
+#define RL_TDESC_CMD_EOF 0x10000000 /* end of frame marker */
+#define RL_TDESC_CMD_SOF 0x20000000 /* start of frame marker */
+#define RL_TDESC_CMD_EOR 0x40000000 /* end of ring marker */
+#define RL_TDESC_CMD_OWN 0x80000000 /* chip owns descriptor */
+
+#define RL_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */
+#define RL_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */
#define RL_TDESC_CMD_UDPCSUMV2 0x80000000
-#define RL_TDESC_CMD_TCPCSUMV2 0x40000000
-#define RL_TDESC_CMD_IPCSUMV2 0x20000000
+#define RL_TDESC_CMD_TCPCSUMV2 0x40000000
+#define RL_TDESC_CMD_IPCSUMV2 0x20000000
/*
* Error bits are valid only on the last descriptor of a frame
* (i.e. RL_TDESC_CMD_EOF == 1)
*/
-#define RL_TDESC_STAT_COLCNT 0x000F0000 /* collision count */
-#define RL_TDESC_STAT_EXCESSCOL 0x00100000 /* excessive collisions */
-#define RL_TDESC_STAT_LINKFAIL 0x00200000 /* link faulure */
-#define RL_TDESC_STAT_OWINCOL 0x00400000 /* out-of-window collision */
-#define RL_TDESC_STAT_TXERRSUM 0x00800000 /* transmit error summary */
-#define RL_TDESC_STAT_UNDERRUN 0x02000000 /* TX underrun occured */
-#define RL_TDESC_STAT_OWN 0x80000000
+#define RL_TDESC_STAT_COLCNT 0x000F0000 /* collision count */
+#define RL_TDESC_STAT_EXCESSCOL 0x00100000 /* excessive collisions */
+#define RL_TDESC_STAT_LINKFAIL 0x00200000 /* link faulure */
+#define RL_TDESC_STAT_OWINCOL 0x00400000 /* out-of-window collision */
+#define RL_TDESC_STAT_TXERRSUM 0x00800000 /* transmit error summary */
+#define RL_TDESC_STAT_UNDERRUN 0x02000000 /* TX underrun occured */
+#define RL_TDESC_STAT_OWN 0x80000000
/*
* RX descriptor cmd/vlan definitions
*/
-#define RL_RDESC_CMD_EOR 0x40000000
-#define RL_RDESC_CMD_OWN 0x80000000
-#define RL_RDESC_CMD_BUFLEN 0x00001FFF
-
-#define RL_RDESC_STAT_OWN 0x80000000
-#define RL_RDESC_STAT_EOR 0x40000000
-#define RL_RDESC_STAT_SOF 0x20000000
-#define RL_RDESC_STAT_EOF 0x10000000
-#define RL_RDESC_STAT_FRALIGN 0x08000000 /* frame alignment error */
-#define RL_RDESC_STAT_MCAST 0x04000000 /* multicast pkt received */
-#define RL_RDESC_STAT_UCAST 0x02000000 /* unicast pkt received */
-#define RL_RDESC_STAT_BCAST 0x01000000 /* broadcast pkt received */
-#define RL_RDESC_STAT_BUFOFLOW 0x00800000 /* out of buffer space */
-#define RL_RDESC_STAT_FIFOOFLOW 0x00400000 /* FIFO overrun */
-#define RL_RDESC_STAT_GIANT 0x00200000 /* pkt > 4096 bytes */
-#define RL_RDESC_STAT_RXERRSUM 0x00100000 /* RX error summary */
-#define RL_RDESC_STAT_RUNT 0x00080000 /* runt packet received */
-#define RL_RDESC_STAT_CRCERR 0x00040000 /* CRC error */
-#define RL_RDESC_STAT_PROTOID 0x00030000 /* Protocol type */
+#define RL_RDESC_CMD_EOR 0x40000000
+#define RL_RDESC_CMD_OWN 0x80000000
+#define RL_RDESC_CMD_BUFLEN 0x00001FFF
+
+#define RL_RDESC_STAT_OWN 0x80000000
+#define RL_RDESC_STAT_EOR 0x40000000
+#define RL_RDESC_STAT_SOF 0x20000000
+#define RL_RDESC_STAT_EOF 0x10000000
+#define RL_RDESC_STAT_FRALIGN 0x08000000 /* frame alignment error */
+#define RL_RDESC_STAT_MCAST 0x04000000 /* multicast pkt received */
+#define RL_RDESC_STAT_UCAST 0x02000000 /* unicast pkt received */
+#define RL_RDESC_STAT_BCAST 0x01000000 /* broadcast pkt received */
+#define RL_RDESC_STAT_BUFOFLOW 0x00800000 /* out of buffer space */
+#define RL_RDESC_STAT_FIFOOFLOW 0x00400000 /* FIFO overrun */
+#define RL_RDESC_STAT_GIANT 0x00200000 /* pkt > 4096 bytes */
+#define RL_RDESC_STAT_RXERRSUM 0x00100000 /* RX error summary */
+#define RL_RDESC_STAT_RUNT 0x00080000 /* runt packet received */
+#define RL_RDESC_STAT_CRCERR 0x00040000 /* CRC error */
+#define RL_RDESC_STAT_PROTOID 0x00030000 /* Protocol type */
#define RL_RDESC_STAT_UDP 0x00020000 /* UDP, 8168C/CP, 8111C/CP */
#define RL_RDESC_STAT_TCP 0x00010000 /* TCP, 8168C/CP, 8111C/CP */
-#define RL_RDESC_STAT_IPSUMBAD 0x00008000 /* IP header checksum bad */
-#define RL_RDESC_STAT_UDPSUMBAD 0x00004000 /* UDP checksum bad */
-#define RL_RDESC_STAT_TCPSUMBAD 0x00002000 /* TCP checksum bad */
-#define RL_RDESC_STAT_FRAGLEN 0x00001FFF /* RX'ed frame/frag len */
-#define RL_RDESC_STAT_GFRAGLEN 0x00003FFF /* RX'ed frame/frag len */
-#define RL_RDESC_STAT_ERRS (RL_RDESC_STAT_GIANT|RL_RDESC_STAT_RUNT| \
+#define RL_RDESC_STAT_IPSUMBAD 0x00008000 /* IP header checksum bad */
+#define RL_RDESC_STAT_UDPSUMBAD 0x00004000 /* UDP checksum bad */
+#define RL_RDESC_STAT_TCPSUMBAD 0x00002000 /* TCP checksum bad */
+#define RL_RDESC_STAT_FRAGLEN 0x00001FFF /* RX'ed frame/frag len */
+#define RL_RDESC_STAT_GFRAGLEN 0x00003FFF /* RX'ed frame/frag len */
+#define RL_RDESC_STAT_ERRS (RL_RDESC_STAT_GIANT|RL_RDESC_STAT_RUNT| \
RL_RDESC_STAT_CRCERR)
-#define RL_RDESC_VLANCTL_TAG 0x00010000 /* VLAN tag available
+#define RL_RDESC_VLANCTL_TAG 0x00010000 /* VLAN tag available
(rl_vlandata valid)*/
-#define RL_RDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
+#define RL_RDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */
#define RL_RDESC_IPV6 0x80000000
#define RL_RDESC_IPV4 0x40000000
-#define RL_PROTOID_NONIP 0x00000000
-#define RL_PROTOID_TCPIP 0x00010000
-#define RL_PROTOID_UDPIP 0x00020000
-#define RL_PROTOID_IP 0x00030000
-#define RL_TCPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \
+#define RL_PROTOID_NONIP 0x00000000
+#define RL_PROTOID_TCPIP 0x00010000
+#define RL_PROTOID_UDPIP 0x00020000
+#define RL_PROTOID_IP 0x00030000
+#define RL_TCPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \
RL_PROTOID_TCPIP)
-#define RL_UDPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \
+#define RL_UDPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \
RL_PROTOID_UDPIP)
/*
@@ -746,7 +747,7 @@ struct rl_stats {
* Descriptor alignment : 256 bytes
* Tx buffer : At least 4 bytes in length.
* Rx buffer : At least 8 bytes in length and 8 bytes alignment required.
- *
+ *
* 8169
* Number of descriptors supported : up to 1024
* Descriptor alignment : 256 bytes
@@ -754,38 +755,38 @@ struct rl_stats {
* Rx buffer : At least 8 bytes in length and 8 bytes alignment required.
*/
#ifndef __NO_STRICT_ALIGNMENT
-#define RE_FIXUP_RX 1
+#define RE_FIXUP_RX 1
#endif
-#define RL_8169_TX_DESC_CNT 256
-#define RL_8169_RX_DESC_CNT 256
-#define RL_8139_TX_DESC_CNT 64
-#define RL_8139_RX_DESC_CNT 64
-#define RL_TX_DESC_CNT RL_8169_TX_DESC_CNT
-#define RL_RX_DESC_CNT RL_8169_RX_DESC_CNT
+#define RL_8169_TX_DESC_CNT 256
+#define RL_8169_RX_DESC_CNT 256
+#define RL_8139_TX_DESC_CNT 64
+#define RL_8139_RX_DESC_CNT 64
+#define RL_TX_DESC_CNT RL_8169_TX_DESC_CNT
+#define RL_RX_DESC_CNT RL_8169_RX_DESC_CNT
#define RL_NTXSEGS 32
-#define RL_RING_ALIGN 256
-#define RL_DUMP_ALIGN 64
-#define RL_IFQ_MAXLEN 512
-#define RL_TX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1))
-#define RL_TX_DESC_PRV(sc,x) ((x - 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1))
-#define RL_RX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_rx_desc_cnt - 1))
-#define RL_OWN(x) (le32toh((x)->rl_cmdstat) & RL_RDESC_STAT_OWN)
-#define RL_RXBYTES(x) (le32toh((x)->rl_cmdstat) & sc->rl_rxlenmask)
-#define RL_PKTSZ(x) ((x)/* >> 3*/)
+#define RL_RING_ALIGN 256
+#define RL_DUMP_ALIGN 64
+#define RL_IFQ_MAXLEN 512
+#define RL_TX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1))
+#define RL_TX_DESC_PRV(sc,x) ((x - 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1))
+#define RL_RX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_rx_desc_cnt - 1))
+#define RL_OWN(x) (le32toh((x)->rl_cmdstat) & RL_RDESC_STAT_OWN)
+#define RL_RXBYTES(x) (le32toh((x)->rl_cmdstat) & sc->rl_rxlenmask)
+#define RL_PKTSZ(x) ((x)/* >> 3*/)
#ifdef RE_FIXUP_RX
-#define RE_ETHER_ALIGN sizeof(uint64_t)
-#define RE_RX_DESC_BUFLEN (MCLBYTES - RE_ETHER_ALIGN)
+#define RE_ETHER_ALIGN sizeof(uint64_t)
+#define RE_RX_DESC_BUFLEN (MCLBYTES - RE_ETHER_ALIGN)
#else
-#define RE_ETHER_ALIGN 0
-#define RE_RX_DESC_BUFLEN MCLBYTES
+#define RE_ETHER_ALIGN 0
+#define RE_RX_DESC_BUFLEN MCLBYTES
#endif
#define RL_MSI_MESSAGES 1
-#define RL_ADDR_LO(y) ((uint64_t) (y) & 0xFFFFFFFF)
-#define RL_ADDR_HI(y) ((uint64_t) (y) >> 32)
+#define RL_ADDR_LO(y) ((uint64_t) (y) & 0xFFFFFFFF)
+#define RL_ADDR_HI(y) ((uint64_t) (y) >> 32)
/*
* The number of bits reserved for MSS in RealTek controllers is
@@ -796,8 +797,8 @@ struct rl_stats {
#define RL_TSO_MTU (2047 - ETHER_HDR_LEN - ETHER_CRC_LEN)
/* see comment in dev/re/if_re.c */
-#define RL_JUMBO_FRAMELEN 7440
-#define RL_JUMBO_MTU (RL_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
+#define RL_JUMBO_FRAMELEN 7440
+#define RL_JUMBO_MTU (RL_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define RL_MAX_FRAMELEN \
(ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
@@ -906,42 +907,42 @@ struct rl_softc {
/*
* register space access macros
*/
-#define CSR_WRITE_STREAM_4(sc, reg, val) \
+#define CSR_WRITE_STREAM_4(sc, reg, val) \
bus_space_write_stream_4(sc->rl_btag, sc->rl_bhandle, reg, val)
-#define CSR_WRITE_4(sc, reg, val) \
+#define CSR_WRITE_4(sc, reg, val) \
bus_space_write_4(sc->rl_btag, sc->rl_bhandle, reg, val)
-#define CSR_WRITE_2(sc, reg, val) \
+#define CSR_WRITE_2(sc, reg, val) \
bus_space_write_2(sc->rl_btag, sc->rl_bhandle, reg, val)
-#define CSR_WRITE_1(sc, reg, val) \
+#define CSR_WRITE_1(sc, reg, val) \
bus_space_write_1(sc->rl_btag, sc->rl_bhandle, reg, val)
-#define CSR_READ_4(sc, reg) \
+#define CSR_READ_4(sc, reg) \
bus_space_read_4(sc->rl_btag, sc->rl_bhandle, reg)
-#define CSR_READ_2(sc, reg) \
+#define CSR_READ_2(sc, reg) \
bus_space_read_2(sc->rl_btag, sc->rl_bhandle, reg)
-#define CSR_READ_1(sc, reg) \
+#define CSR_READ_1(sc, reg) \
bus_space_read_1(sc->rl_btag, sc->rl_bhandle, reg)
-#define CSR_SETBIT_1(sc, offset, val) \
+#define CSR_SETBIT_1(sc, offset, val) \
CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) | (val))
-#define CSR_CLRBIT_1(sc, offset, val) \
+#define CSR_CLRBIT_1(sc, offset, val) \
CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) & ~(val))
-#define CSR_SETBIT_2(sc, offset, val) \
+#define CSR_SETBIT_2(sc, offset, val) \
CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) | (val))
-#define CSR_CLRBIT_2(sc, offset, val) \
+#define CSR_CLRBIT_2(sc, offset, val) \
CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) & ~(val))
-#define CSR_SETBIT_4(sc, offset, val) \
+#define CSR_SETBIT_4(sc, offset, val) \
CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) | (val))
-#define CSR_CLRBIT_4(sc, offset, val) \
+#define CSR_CLRBIT_4(sc, offset, val) \
CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) & ~(val))
-#define RL_TIMEOUT 1000
-#define RL_PHY_TIMEOUT 2000
+#define RL_TIMEOUT 1000
+#define RL_PHY_TIMEOUT 2000
/*
* General constants that are fun to know.
@@ -953,197 +954,162 @@ struct rl_softc {
/*
* RealTek chip device IDs.
*/
-#define RT_DEVICEID_8139D 0x8039
+#define RT_DEVICEID_8139D 0x8039
#define RT_DEVICEID_8129 0x8129
-#define RT_DEVICEID_8101E 0x8136
+#define RT_DEVICEID_8101E 0x8136
#define RT_DEVICEID_8138 0x8138
#define RT_DEVICEID_8139 0x8139
-#define RT_DEVICEID_8169SC 0x8167
-#define RT_DEVICEID_8168 0x8168
-#define RT_DEVICEID_8169 0x8169
-#define RT_DEVICEID_8100 0x8100
+#define RT_DEVICEID_8169SC 0x8167
+#define RT_DEVICEID_8168 0x8168
+#define RT_DEVICEID_8169 0x8169
+#define RT_DEVICEID_8100 0x8100
-#define RT_REVID_8139CPLUS 0x20
+#define RT_REVID_8139CPLUS 0x20
/*
* Accton PCI vendor ID
*/
-#define ACCTON_VENDORID 0x1113
+#define ACCTON_VENDORID 0x1113
/*
* Accton MPX 5030/5038 device ID.
*/
-#define ACCTON_DEVICEID_5030 0x1211
+#define ACCTON_DEVICEID_5030 0x1211
/*
* Nortel PCI vendor ID
*/
-#define NORTEL_VENDORID 0x126C
+#define NORTEL_VENDORID 0x126C
/*
* Delta Electronics Vendor ID.
*/
-#define DELTA_VENDORID 0x1500
+#define DELTA_VENDORID 0x1500
/*
* Delta device IDs.
*/
-#define DELTA_DEVICEID_8139 0x1360
+#define DELTA_DEVICEID_8139 0x1360
/*
* Addtron vendor ID.
*/
-#define ADDTRON_VENDORID 0x4033
+#define ADDTRON_VENDORID 0x4033
/*
* Addtron device IDs.
*/
-#define ADDTRON_DEVICEID_8139 0x1360
+#define ADDTRON_DEVICEID_8139 0x1360
/*
* D-Link vendor ID.
*/
-#define DLINK_VENDORID 0x1186
+#define DLINK_VENDORID 0x1186
/*
* D-Link DFE-530TX+ device ID
*/
-#define DLINK_DEVICEID_530TXPLUS 0x1300
+#define DLINK_DEVICEID_530TXPLUS 0x1300
/*
* D-Link DFE-5280T device ID
*/
-#define DLINK_DEVICEID_528T 0x4300
+#define DLINK_DEVICEID_528T 0x4300
/*
* D-Link DFE-690TXD device ID
*/
-#define DLINK_DEVICEID_690TXD 0x1340
+#define DLINK_DEVICEID_690TXD 0x1340
/*
* Corega K.K vendor ID
*/
-#define COREGA_VENDORID 0x1259
+#define COREGA_VENDORID 0x1259
/*
* Corega FEther CB-TXD device ID
*/
-#define COREGA_DEVICEID_FETHERCBTXD 0xa117
+#define COREGA_DEVICEID_FETHERCBTXD 0xa117
/*
* Corega FEtherII CB-TXD device ID
*/
-#define COREGA_DEVICEID_FETHERIICBTXD 0xa11e
+#define COREGA_DEVICEID_FETHERIICBTXD 0xa11e
/*
* Corega CG-LAPCIGT device ID
*/
-#define COREGA_DEVICEID_CGLAPCIGT 0xc107
+#define COREGA_DEVICEID_CGLAPCIGT 0xc107
/*
* Linksys vendor ID
*/
-#define LINKSYS_VENDORID 0x1737
+#define LINKSYS_VENDORID 0x1737
/*
* Linksys EG1032 device ID
*/
-#define LINKSYS_DEVICEID_EG1032 0x1032
+#define LINKSYS_DEVICEID_EG1032 0x1032
/*
* Linksys EG1032 rev 3 sub-device ID
*/
-#define LINKSYS_SUBDEVICE_EG1032_REV3 0x0024
+#define LINKSYS_SUBDEVICE_EG1032_REV3 0x0024
/*
* Peppercon vendor ID
*/
-#define PEPPERCON_VENDORID 0x1743
+#define PEPPERCON_VENDORID 0x1743
/*
* Peppercon ROL-F device ID
*/
-#define PEPPERCON_DEVICEID_ROLF 0x8139
+#define PEPPERCON_DEVICEID_ROLF 0x8139
/*
* Planex Communications, Inc. vendor ID
*/
-#define PLANEX_VENDORID 0x14ea
+#define PLANEX_VENDORID 0x14ea
/*
* Planex FNW-3603-TX device ID
*/
-#define PLANEX_DEVICEID_FNW3603TX 0xab06
+#define PLANEX_DEVICEID_FNW3603TX 0xab06
/*
* Planex FNW-3800-TX device ID
*/
-#define PLANEX_DEVICEID_FNW3800TX 0xab07
+#define PLANEX_DEVICEID_FNW3800TX 0xab07
/*
* LevelOne vendor ID
*/
-#define LEVEL1_VENDORID 0x018A
+#define LEVEL1_VENDORID 0x018A
/*
* LevelOne FPC-0106TX devide ID
*/
-#define LEVEL1_DEVICEID_FPC0106TX 0x0106
+#define LEVEL1_DEVICEID_FPC0106TX 0x0106
/*
* Compaq vendor ID
*/
-#define CP_VENDORID 0x021B
+#define CP_VENDORID 0x021B
/*
* Edimax vendor ID
*/
-#define EDIMAX_VENDORID 0x13D1
+#define EDIMAX_VENDORID 0x13D1
/*
* Edimax EP-4103DL cardbus device ID
*/
-#define EDIMAX_DEVICEID_EP4103DL 0xAB06
+#define EDIMAX_DEVICEID_EP4103DL 0xAB06
/* US Robotics vendor ID */
-#define USR_VENDORID 0x16EC
+#define USR_VENDORID 0x16EC
/* US Robotics 997902 device ID */
-#define USR_DEVICEID_997902 0x0116
-
-/*
- * PCI low memory base and low I/O base register, and
- * other PCI registers.
- */
-
-#define RL_PCI_VENDOR_ID 0x00
-#define RL_PCI_DEVICE_ID 0x02
-#define RL_PCI_COMMAND 0x04
-#define RL_PCI_STATUS 0x06
-#define RL_PCI_CLASSCODE 0x09
-#define RL_PCI_LATENCY_TIMER 0x0D
-#define RL_PCI_HEADER_TYPE 0x0E
-#define RL_PCI_LOIO 0x10
-#define RL_PCI_LOMEM 0x14
-#define RL_PCI_BIOSROM 0x30
-#define RL_PCI_INTLINE 0x3C
-#define RL_PCI_INTPIN 0x3D
-#define RL_PCI_MINGNT 0x3E
-#define RL_PCI_MINLAT 0x0F
-#define RL_PCI_RESETOPT 0x48
-#define RL_PCI_EEPROM_DATA 0x4C
-
-#define RL_PCI_CAPID 0x50 /* 8 bits */
-#define RL_PCI_NEXTPTR 0x51 /* 8 bits */
-#define RL_PCI_PWRMGMTCAP 0x52 /* 16 bits */
-#define RL_PCI_PWRMGMTCTRL 0x54 /* 16 bits */
-
-#define RL_PSTATE_MASK 0x0003
-#define RL_PSTATE_D0 0x0000
-#define RL_PSTATE_D1 0x0002
-#define RL_PSTATE_D2 0x0002
-#define RL_PSTATE_D3 0x0003
-#define RL_PME_EN 0x0010
-#define RL_PME_STATUS 0x8000
+#define USR_DEVICEID_997902 0x0116
diff --git a/sys/powerpc/aim/clock.c b/sys/powerpc/aim/clock.c
index eb3337c..0bf7cfa 100644
--- a/sys/powerpc/aim/clock.c
+++ b/sys/powerpc/aim/clock.c
@@ -105,7 +105,7 @@ static struct timecounter decr_tc = {
};
/*
- * Decrementor interrupt handler.
+ * Decrementer interrupt handler.
*/
void
decr_intr(struct trapframe *frame)
diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c
index 0331b50..f52f7a4 100644
--- a/sys/powerpc/aim/machdep.c
+++ b/sys/powerpc/aim/machdep.c
@@ -245,6 +245,9 @@ extern void *dsitrap, *dsisize;
extern void *decrint, *decrsize;
extern void *extint, *extsize;
extern void *dblow, *dbsize;
+extern void *imisstrap, *imisssize;
+extern void *dlmisstrap, *dlmisssize;
+extern void *dsmisstrap, *dsmisssize;
uintptr_t
powerpc_init(vm_offset_t startkernel, vm_offset_t endkernel,
@@ -491,6 +494,12 @@ powerpc_init(vm_offset_t startkernel, vm_offset_t endkernel,
bcopy(generictrap, (void *)EXC_VEC, (size_t)&trapsize);
bcopy(generictrap, (void *)EXC_VECAST_G4, (size_t)&trapsize);
bcopy(generictrap, (void *)EXC_VECAST_G5, (size_t)&trapsize);
+ #ifndef __powerpc64__
+ /* G2-specific TLB miss helper handlers */
+ bcopy(&imisstrap, (void *)EXC_IMISS, (size_t)&imisssize);
+ bcopy(&dlmisstrap, (void *)EXC_DLMISS, (size_t)&dlmisssize);
+ bcopy(&dsmisstrap, (void *)EXC_DSMISS, (size_t)&dsmisssize);
+ #endif
__syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
/*
diff --git a/sys/powerpc/aim/mmu_oea64.c b/sys/powerpc/aim/mmu_oea64.c
index cfb822e..3e336c9 100644
--- a/sys/powerpc/aim/mmu_oea64.c
+++ b/sys/powerpc/aim/mmu_oea64.c
@@ -274,7 +274,6 @@ static struct mem_region *regions;
static struct mem_region *pregions;
static u_int phys_avail_count;
static int regions_sz, pregions_sz;
-extern int ofw_real_mode;
extern struct pmap ofw_pmap;
@@ -1118,7 +1117,8 @@ moea64_bootstrap(mmu_t mmup, vm_offset_t kernelstart, vm_offset_t kernelend)
* mode.
*/
- if (!ofw_real_mode) {
+ chosen = OF_finddevice("/chosen");
+ if (chosen != -1 && OF_getprop(chosen, "mmu", &mmui, 4) != -1) {
#ifndef __powerpc64__
moea64_pinit(mmup, &ofw_pmap);
@@ -1126,10 +1126,6 @@ moea64_bootstrap(mmu_t mmup, vm_offset_t kernelstart, vm_offset_t kernelend)
ofw_pmap.pm_sr[i] = kernel_pmap->pm_sr[i];
#endif
- if ((chosen = OF_finddevice("/chosen")) == -1)
- panic("moea64_bootstrap: can't find /chosen");
- OF_getprop(chosen, "mmu", &mmui, 4);
-
if ((mmu = OF_instance_to_package(mmui)) == -1)
panic("moea64_bootstrap: can't get mmu package");
if ((sz = OF_getproplen(mmu, "translations")) == -1)
diff --git a/sys/powerpc/aim/nexus.c b/sys/powerpc/aim/nexus.c
index b17de11..203ae81 100644
--- a/sys/powerpc/aim/nexus.c
+++ b/sys/powerpc/aim/nexus.c
@@ -213,9 +213,6 @@ nexus_attach(device_t dev)
struct nexus_softc *sc;
u_long start, end;
- if ((root = OF_peer(0)) == -1)
- panic("nexus_probe: OF_peer failed.");
-
sc = device_get_softc(dev);
start = 0;
@@ -229,6 +226,9 @@ nexus_attach(device_t dev)
rman_manage_region(&sc->sc_rman, start, end))
panic("nexus_probe IRQ rman");
+ if ((root = OF_peer(0)) == 0)
+ return (bus_generic_attach(dev));
+
/*
* Now walk the OFW tree to locate top-level devices
*/
diff --git a/sys/powerpc/aim/ofw_machdep.c b/sys/powerpc/aim/ofw_machdep.c
index e0bf505..1ebcd0c 100644
--- a/sys/powerpc/aim/ofw_machdep.c
+++ b/sys/powerpc/aim/ofw_machdep.c
@@ -333,6 +333,12 @@ OF_initial_setup(void *fdt_ptr, void *junk, int (*openfirm)(void *))
#endif
fdt = fdt_ptr;
+
+ #ifdef FDT_DTB_STATIC
+ /* Check for a statically included blob */
+ if (fdt == NULL)
+ fdt = &fdt_static_dtb;
+ #endif
}
boolean_t
@@ -361,7 +367,7 @@ OF_bootstrap()
* background processes.
*/
ofw_quiesce();
- } else {
+ } else if (fdt != NULL) {
status = OF_install(OFW_FDT, 0);
if (status != TRUE)
diff --git a/sys/powerpc/aim/trap_subr32.S b/sys/powerpc/aim/trap_subr32.S
index 1cefc28..7c154a8 100644
--- a/sys/powerpc/aim/trap_subr32.S
+++ b/sys/powerpc/aim/trap_subr32.S
@@ -362,6 +362,207 @@ CNAME(alitrap):
CNAME(alisize) = .-CNAME(alitrap)
/*
+ * G2 specific: instuction TLB miss.
+ */
+ .globl CNAME(imisstrap),CNAME(imisssize)
+CNAME(imisstrap):
+ mfspr %r2, SPR_HASH1 /* get first pointer */
+ addi %r1, 0, 8 /* load 8 for counter */
+ mfctr %r0 /* save counter */
+ mfspr %r3, SPR_ICMP /* get first compare value */
+ addi %r2, %r2, -8 /* pre dec the pointer */
+im0:
+ mtctr %r1 /* load counter */
+im1:
+ lwzu %r1, 8(%r2) /* get next pte */
+ cmp 0, %r1, %r3 /* see if found pte */
+ bdnzf 2, im1 /* dec count br if cmp ne and if
+ * count not zero */
+ bne instr_sec_hash /* if not found set up second hash
+ * or exit */
+ lwz %r1, +4(%r2) /* load tlb entry lower-word */
+ andi. %r3, %r1, 8 /* check G bit */
+ bne do_isi_prot /* if guarded, take an ISI */
+ mtctr %r0 /* restore counter */
+ mfspr %r0, SPR_IMISS /* get the miss address for the tlbli */
+ mfspr %r3, SPR_SRR1 /* get the saved cr0 bits */
+ mtcrf 0x80, %r3 /* restore CR0 */
+ mtspr SPR_RPA, %r1 /* set the pte */
+ ori %r1, %r1, 0x100 /* set reference bit */
+ srwi %r1, %r1, 8 /* get byte 7 of pte */
+ tlbli %r0 /* load the itlb */
+ stb %r1, +6(%r2) /* update page table */
+ rfi /* return to executing program */
+
+instr_sec_hash:
+ andi. %r1, %r3, 0x0040 /* see if we have done second hash */
+ bne do_isi /* if so, go to ISI interrupt */
+ mfspr %r2, SPR_HASH2 /* get the second pointer */
+ ori %r3, %r3, 0x0040 /* change the compare value */
+ addi %r1, %r0, 8 /* load 8 for counter */
+ addi %r2, %r2, -8 /* pre dec for update on load */
+ b im0 /* try second hash */
+
+/* Create a faked ISI interrupt as the address was not found */
+do_isi_prot:
+ mfspr %r3, SPR_SRR1 /* get srr1 */
+ andi. %r2, %r3, 0xffff /* clean upper srr1 */
+ addis %r2, %r2, 0x0800 /* or in srr<4> = 1 to flag prot
+ * violation */
+ b isi1
+do_isi:
+ mfspr %r3, SPR_SRR1 /* get srr1 */
+ andi. %r2, %r3, 0xffff /* clean srr1 */
+ addis %r2, %r2, 0x4000 /* or in srr1<1> = 1 to flag pte
+ * not found */
+isi1:
+ mtctr %r0 /* restore counter */
+ mtspr SPR_SRR1, %r2 /* set srr1 */
+ mfmsr %r0 /* get msr */
+ xoris %r0, %r0, 0x2 /* flip the msr<tgpr> bit */
+ mtcrf 0x80, %r3 /* restore CR0 */
+ mtmsr %r0 /* flip back to the native gprs */
+ ba EXC_ISI /* go to instr. access interrupt */
+
+CNAME(imisssize) = .-CNAME(imisstrap)
+
+/*
+ * G2 specific: data load TLB miss.
+ */
+ .globl CNAME(dlmisstrap),CNAME(dlmisssize)
+CNAME(dlmisstrap):
+ mfspr %r2, SPR_HASH1 /* get first pointer */
+ addi %r1, 0, 8 /* load 8 for counter */
+ mfctr %r0 /* save counter */
+ mfspr %r3, SPR_DCMP /* get first compare value */
+ addi %r2, %r2, -8 /* pre dec the pointer */
+dm0:
+ mtctr %r1 /* load counter */
+dm1:
+ lwzu %r1, 8(%r2) /* get next pte */
+ cmp 0, 0, %r1, %r3 /* see if found pte */
+ bdnzf 2, dm1 /* dec count br if cmp ne and if
+ * count not zero */
+ bne data_sec_hash /* if not found set up second hash
+ * or exit */
+ lwz %r1, +4(%r2) /* load tlb entry lower-word */
+ mtctr %r0 /* restore counter */
+ mfspr %r0, SPR_DMISS /* get the miss address for the tlbld */
+ mfspr %r3, SPR_SRR1 /* get the saved cr0 bits */
+ mtcrf 0x80, %r3 /* restore CR0 */
+ mtspr SPR_RPA, %r1 /* set the pte */
+ ori %r1, %r1, 0x100 /* set reference bit */
+ srwi %r1, %r1, 8 /* get byte 7 of pte */
+ tlbld %r0 /* load the dtlb */
+ stb %r1, +6(%r2) /* update page table */
+ rfi /* return to executing program */
+
+data_sec_hash:
+ andi. %r1, %r3, 0x0040 /* see if we have done second hash */
+ bne do_dsi /* if so, go to DSI interrupt */
+ mfspr %r2, SPR_HASH2 /* get the second pointer */
+ ori %r3, %r3, 0x0040 /* change the compare value */
+ addi %r1, 0, 8 /* load 8 for counter */
+ addi %r2, %r2, -8 /* pre dec for update on load */
+ b dm0 /* try second hash */
+
+CNAME(dlmisssize) = .-CNAME(dlmisstrap)
+
+/*
+ * G2 specific: data store TLB miss.
+ */
+ .globl CNAME(dsmisstrap),CNAME(dsmisssize)
+CNAME(dsmisstrap):
+ mfspr %r2, SPR_HASH1 /* get first pointer */
+ addi %r1, 0, 8 /* load 8 for counter */
+ mfctr %r0 /* save counter */
+ mfspr %r3, SPR_DCMP /* get first compare value */
+ addi %r2, %r2, -8 /* pre dec the pointer */
+ds0:
+ mtctr %r1 /* load counter */
+ds1:
+ lwzu %r1, 8(%r2) /* get next pte */
+ cmp 0, 0, %r1, %r3 /* see if found pte */
+ bdnzf 2, ds1 /* dec count br if cmp ne and if
+ * count not zero */
+ bne data_store_sec_hash /* if not found set up second hash
+ * or exit */
+ lwz %r1, +4(%r2) /* load tlb entry lower-word */
+ andi. %r3, %r1, 0x80 /* check the C-bit */
+ beq data_store_chk_prot /* if (C==0)
+ * go check protection modes */
+ds2:
+ mtctr %r0 /* restore counter */
+ mfspr %r0, SPR_DMISS /* get the miss address for the tlbld */
+ mfspr %r3, SPR_SRR1 /* get the saved cr0 bits */
+ mtcrf 0x80, %r3 /* restore CR0 */
+ mtspr SPR_RPA, %r1 /* set the pte */
+ tlbld %r0 /* load the dtlb */
+ rfi /* return to executing program */
+
+data_store_sec_hash:
+ andi. %r1, %r3, 0x0040 /* see if we have done second hash */
+ bne do_dsi /* if so, go to DSI interrupt */
+ mfspr %r2, SPR_HASH2 /* get the second pointer */
+ ori %r3, %r3, 0x0040 /* change the compare value */
+ addi %r1, 0, 8 /* load 8 for counter */
+ addi %r2, %r2, -8 /* pre dec for update on load */
+ b ds0 /* try second hash */
+
+/* Check the protection before setting PTE(c-bit) */
+data_store_chk_prot:
+ rlwinm. %r3,%r1,30,0,1 /* test PP */
+ bge- chk0 /* if (PP == 00 or PP == 01)
+ * goto chk0: */
+ andi. %r3, %r1, 1 /* test PP[0] */
+ beq+ chk2 /* return if PP[0] == 0 */
+ b do_dsi_prot /* else DSIp */
+chk0:
+ mfspr %r3,SPR_SRR1 /* get old msr */
+ andis. %r3,%r3,0x0008 /* test the KEY bit (SRR1-bit 12) */
+ beq chk2 /* if (KEY==0) goto chk2: */
+ b do_dsi_prot /* else do_dsi_prot */
+chk2:
+ ori %r1, %r1, 0x180 /* set reference and change bit */
+ sth %r1, 6(%r2) /* update page table */
+ b ds2 /* and back we go */
+
+/* Create a faked DSI interrupt as the address was not found */
+do_dsi:
+ mfspr %r3, SPR_SRR1 /* get srr1 */
+ rlwinm %r1,%r3,9,6,6 /* get srr1<flag> to bit 6 for
+ * load/store, zero rest */
+ addis %r1, %r1, 0x4000 /* or in dsisr<1> = 1 to flag pte
+ * not found */
+ b dsi1
+
+do_dsi_prot:
+ mfspr %r3, SPR_SRR1 /* get srr1 */
+ rlwinm %r1,%r3,9,6,6 /* get srr1<flag> to bit 6 for
+ *load/store, zero rest */
+ addis %r1, %r1, 0x0800 /* or in dsisr<4> = 1 to flag prot
+ * violation */
+
+dsi1:
+ mtctr %r0 /* restore counter */
+ andi. %r2, %r3, 0xffff /* clear upper bits of srr1 */
+ mtspr SPR_SRR1, %r2 /* set srr1 */
+ mtspr SPR_DSISR, %r1 /* load the dsisr */
+ mfspr %r1, SPR_DMISS /* get miss address */
+ rlwinm. %r2,%r2,0,31,31 /* test LE bit */
+ beq dsi2 /* if little endian then: */
+ xor %r1, %r1, 0x07 /* de-mung the data address */
+dsi2:
+ mtspr SPR_DAR, %r1 /* put in dar */
+ mfmsr %r0 /* get msr */
+ xoris %r0, %r0, 0x2 /* flip the msr<tgpr> bit */
+ mtcrf 0x80, %r3 /* restore CR0 */
+ mtmsr %r0 /* flip back to the native gprs */
+ ba EXC_DSI /* branch to DSI interrupt */
+
+CNAME(dsmisssize) = .-CNAME(dsmisstrap)
+
+/*
* Similar to the above for DSI
* Has to handle BAT spills
* and standard pagetable spills
diff --git a/sys/powerpc/booke/clock.c b/sys/powerpc/booke/clock.c
index a50a504..9958160 100644
--- a/sys/powerpc/booke/clock.c
+++ b/sys/powerpc/booke/clock.c
@@ -108,7 +108,7 @@ static struct timecounter decr_timecounter = {
};
/*
- * Decrementor interrupt handler.
+ * Decrementer interrupt handler.
*/
void
decr_intr(struct trapframe *frame)
diff --git a/sys/powerpc/booke/locore.S b/sys/powerpc/booke/locore.S
index ae45baf..3ac4a1a 100644
--- a/sys/powerpc/booke/locore.S
+++ b/sys/powerpc/booke/locore.S
@@ -28,8 +28,6 @@
#include "assym.s"
-#include <sys/mutex.h>
-
#include <machine/asm.h>
#include <machine/hid.h>
#include <machine/param.h>
diff --git a/sys/powerpc/booke/machdep.c b/sys/powerpc/booke/machdep.c
index d216292..b8a77a5 100644
--- a/sys/powerpc/booke/machdep.c
+++ b/sys/powerpc/booke/machdep.c
@@ -453,7 +453,7 @@ cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
ptr = &tlb0_miss_locks[cpuid * words_per_gran];
pcpu->pc_booke_tlb_lock = ptr;
- *ptr = MTX_UNOWNED;
+ *ptr = TLB_UNLOCKED;
*(ptr + 1) = 0; /* recurse counter */
#endif
}
diff --git a/sys/powerpc/booke/pmap.c b/sys/powerpc/booke/pmap.c
index c5e285c..abe8ad5 100644
--- a/sys/powerpc/booke/pmap.c
+++ b/sys/powerpc/booke/pmap.c
@@ -162,8 +162,6 @@ unsigned int kernel_ptbls; /* Number of KVA ptbls. */
#define PMAP_REMOVE_DONE(pmap) \
((pmap) != kernel_pmap && (pmap)->pm_stats.resident_count == 0)
-extern void tlb_lock(uint32_t *);
-extern void tlb_unlock(uint32_t *);
extern void tid_flush(tlbtid_t);
/**************************************************************************/
diff --git a/sys/powerpc/booke/trap_subr.S b/sys/powerpc/booke/trap_subr.S
index b71f4bd..c3b856a 100644
--- a/sys/powerpc/booke/trap_subr.S
+++ b/sys/powerpc/booke/trap_subr.S
@@ -330,7 +330,7 @@
lwz %r22, PC_BOOKE_TLB_LOCK(%r20); \
\
1: lwarx %r23, 0, %r22; \
- cmpwi %r23, MTX_UNOWNED; \
+ cmpwi %r23, TLB_UNLOCKED; \
beq 2f; \
\
/* check if this is recursion */ \
@@ -364,7 +364,7 @@
msync; \
\
/* release the lock */ \
- li %r23, MTX_UNOWNED; \
+ li %r23, TLB_UNLOCKED; \
stw %r23, 0(%r22); \
1: isync; \
msync
@@ -860,7 +860,7 @@ ENTRY(tlb_lock)
GET_CPUINFO(%r5)
lwz %r5, PC_CURTHREAD(%r5)
1: lwarx %r4, 0, %r3
- cmpwi %r4, MTX_UNOWNED
+ cmpwi %r4, TLB_UNLOCKED
bne 1b
stwcx. %r5, 0, %r3
bne- 1b
@@ -871,11 +871,12 @@ ENTRY(tlb_lock)
ENTRY(tlb_unlock)
isync
msync
- li %r4, MTX_UNOWNED
+ li %r4, TLB_UNLOCKED
stw %r4, 0(%r3)
isync
msync
blr
+
/*
* TLB miss spin locks. For each CPU we have a reservation granule (32 bytes);
* only a single word from this granule will actually be used as a spin lock
diff --git a/sys/powerpc/include/mutex.h b/sys/powerpc/include/mutex.h
deleted file mode 100644
index b6f80fb..0000000
--- a/sys/powerpc/include/mutex.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * Copyright (c) 1997 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.
- * 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. Berkeley Software Design Inc's name may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * 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.
- *
- * from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $
- * $FreeBSD$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#if 0
-#ifdef LOCORE
-
-/*
- * Simple assembly macros to get and release non-recursive spin locks
- */
-#define MTX_ENTER(lck) \
- mfmsr r10; \ /* disable interrupts */
- rlwinm r0, r10, 0, 17, 15; \
- mtmsr r0; \
-1: li r11, MTX_LOCK; \ /* MTX_LOCK offset */
- lwarx r0, r11, lck; \ /* load current lock value */
- cmplwi r0, r1, MTX_UNOWNED; \ /* compare with unowned */
- beq 1; \ /* if owned, loop */
- lwz r0, PC_CURPROC(pcpup); \ /* load curproc */
- stwcx. r0, r11, lck; \ /* attempt to store */
- beq 1; \ /* loop if failed */
- sync; \ /* sync */
- eieio; \ /* sync */
- stw r10, MTX_SAVEINTR(lck) /* save flags */
-
-#define MTX_EXIT(lck) \
- sync; \ /* sync */
- eieio; \ /* sync */
- li r0, MTX_UNOWNED; \ /* load in unowned */
- stw r0, MTX_LOCK(lck); \ /* store to lock */
- lwz r0, MTX_SAVEINTR(lck); \ /* load saved flags */
- mtmsr r0 /* enable interrupts */
-
-#endif /* !LOCORE */
-
-#endif
-#endif /* __MACHINE_MUTEX_H */
diff --git a/sys/powerpc/include/tlb.h b/sys/powerpc/include/tlb.h
index b8913c5..56f5521 100644
--- a/sys/powerpc/include/tlb.h
+++ b/sys/powerpc/include/tlb.h
@@ -129,6 +129,8 @@
#define TID_MAX 255
#define TID_NONE -1
+#define TLB_UNLOCKED 0
+
#if !defined(LOCORE)
typedef struct tlb_entry {
uint32_t mas1;
@@ -146,6 +148,9 @@ void tlb1_init(vm_offset_t);
void tlb1_print_entries(void);
void tlb1_print_tlbentries(void);
+void tlb_lock(uint32_t *);
+void tlb_unlock(uint32_t *);
+
#endif /* !LOCORE */
#endif /* _MACHINE_TLB_H_ */
diff --git a/sys/powerpc/powermac/smu.c b/sys/powerpc/powermac/smu.c
index 2894904..31fb09f 100644
--- a/sys/powerpc/powermac/smu.c
+++ b/sys/powerpc/powermac/smu.c
@@ -96,6 +96,7 @@ struct smu_softc {
struct resource *sc_memr;
int sc_memrid;
+ int sc_u3;
bus_dma_tag_t sc_dmatag;
bus_space_tag_t sc_bt;
@@ -275,6 +276,10 @@ smu_attach(device_t dev)
sc->sc_cur_cmd = NULL;
sc->sc_doorbellirqid = -1;
+ sc->sc_u3 = 0;
+ if (OF_finddevice("/u3") != -1)
+ sc->sc_u3 = 1;
+
/*
* Map the mailbox area. This should be determined from firmware,
* but I have not found a simple way to do that.
@@ -417,7 +422,9 @@ smu_send_cmd(device_t dev, struct smu_cmd *cmd)
mtx_assert(&sc->sc_mtx, MA_OWNED);
- powerpc_pow_enabled = 0; /* SMU cannot work if we go to NAP */
+ if (sc->sc_u3)
+ powerpc_pow_enabled = 0; /* SMU cannot work if we go to NAP */
+
sc->sc_cur_cmd = cmd;
/* Copy the command to the mailbox */
@@ -464,7 +471,8 @@ smu_doorbell_intr(void *xdev)
sizeof(sc->sc_cmd->data));
wakeup(sc->sc_cur_cmd);
sc->sc_cur_cmd = NULL;
- powerpc_pow_enabled = 1;
+ if (sc->sc_u3)
+ powerpc_pow_enabled = 1;
done:
/* Queue next command if one is pending */
diff --git a/sys/powerpc/powerpc/cpu.c b/sys/powerpc/powerpc/cpu.c
index 86fd323..4bbfcac 100644
--- a/sys/powerpc/powerpc/cpu.c
+++ b/sys/powerpc/powerpc/cpu.c
@@ -455,8 +455,8 @@ cpu_970_setup(int cpuid, uint16_t vers)
/* Configure power-saving mode */
switch (vers) {
case IBM970MP:
- hid0_hi |= (HID0_DEEPNAP | HID0_DPM);
- hid0_hi &= ~(HID0_DOZE | HID0_NAP);
+ hid0_hi |= (HID0_DEEPNAP | HID0_NAP | HID0_DPM);
+ hid0_hi &= ~HID0_DOZE;
break;
default:
hid0_hi |= (HID0_NAP | HID0_DPM);
diff --git a/sys/security/mac_portacl/mac_portacl.c b/sys/security/mac_portacl/mac_portacl.c
index f54319a..dbadff8 100644
--- a/sys/security/mac_portacl/mac_portacl.c
+++ b/sys/security/mac_portacl/mac_portacl.c
@@ -133,7 +133,7 @@ struct rule {
/*
* Text format for the rule string is that a rule consists of a
- * comma-seperated list of elements. Each element is in the form
+ * comma-separated list of elements. Each element is in the form
* idtype:id:protocol:portnumber, and constitutes granting of permission
* for the specified binding.
*/
diff --git a/sys/sparc64/include/mutex.h b/sys/sparc64/include/mutex.h
deleted file mode 100644
index c9b2e1d..0000000
--- a/sys/sparc64/include/mutex.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-
- * Copyright (c) 2001 Jake Burkholder.
- * 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$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#endif /* !_MACHINE_MUTEX_H_ */
diff --git a/sys/sparc64/include/vmparam.h b/sys/sparc64/include/vmparam.h
index b9ce546..b92312e 100644
--- a/sys/sparc64/include/vmparam.h
+++ b/sys/sparc64/include/vmparam.h
@@ -128,10 +128,17 @@
#endif
/*
- * Disable superpage reservations.
+ * Enable superpage reservations: 1 level.
*/
#ifndef VM_NRESERVLEVEL
-#define VM_NRESERVLEVEL 0
+#define VM_NRESERVLEVEL 1
+#endif
+
+/*
+ * Level 0 reservations consist of 512 pages.
+ */
+#ifndef VM_LEVEL_0_ORDER
+#define VM_LEVEL_0_ORDER 9
#endif
/*
diff --git a/sys/sun4v/include/mutex.h b/sys/sun4v/include/mutex.h
deleted file mode 100644
index c9b2e1d..0000000
--- a/sys/sun4v/include/mutex.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-
- * Copyright (c) 2001 Jake Burkholder.
- * 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$
- */
-
-#ifndef _MACHINE_MUTEX_H_
-#define _MACHINE_MUTEX_H_
-
-#endif /* !_MACHINE_MUTEX_H_ */
diff --git a/sys/sun4v/include/pmap.h b/sys/sun4v/include/pmap.h
index 6acebb4..aa3f9e1 100644
--- a/sys/sun4v/include/pmap.h
+++ b/sys/sun4v/include/pmap.h
@@ -54,7 +54,6 @@
#define TSB_MAX_RESIZE (20 - TSB_INIT_SHIFT - PAGE_SHIFT)
typedef struct pmap *pmap_t;
-typedef uint32_t pmap_cpumask_t;
struct pv_entry;
struct tte_hash;
@@ -77,8 +76,8 @@ struct pmap {
struct hv_tsb_info pm_tsb;
uint32_t pm_gen_count; /* generation count (pmap lock dropped) */
u_int pm_retries;
- pmap_cpumask_t pm_active; /* mask of cpus currently using pmap */
- pmap_cpumask_t pm_tlbactive; /* mask of cpus that have used this pmap */
+ cpumask_t pm_active; /* mask of cpus currently using pmap */
+ cpumask_t pm_tlbactive; /* mask of cpus that have used this pmap */
struct pmap_statistics pm_stats;
uint32_t pm_tsb_miss_count;
uint32_t pm_tsb_cap_miss_count;
diff --git a/sys/sun4v/include/smp.h b/sys/sun4v/include/smp.h
index 3202089..c075cac 100644
--- a/sys/sun4v/include/smp.h
+++ b/sys/sun4v/include/smp.h
@@ -75,7 +75,7 @@ struct pcpu;
void cpu_mp_bootstrap(struct pcpu *pc);
void cpu_mp_shutdown(void);
-void cpu_ipi_selected(int cpus, uint16_t *cpulist, u_long d0, u_long d1, u_long d2, uint64_t *ackmask);
+void cpu_ipi_selected(int cpu_count, uint16_t *cpulist, u_long d0, u_long d1, u_long d2, uint64_t *ackmask);
void cpu_ipi_send(u_int mid, u_long d0, u_long d1, u_long d2);
void cpu_ipi_ast(struct trapframe *tf);
@@ -85,7 +85,7 @@ void cpu_ipi_hardclock(struct trapframe *tf);
void ipi_all_but_self(u_int ipi);
void ipi_cpu(int cpu, u_int ipi);
-void ipi_selected(u_int cpus, u_int ipi);
+void ipi_selected(cpumask_t cpus, u_int ipi);
vm_offset_t mp_tramp_alloc(void);
void mp_set_tsb_desc_ra(vm_paddr_t);
@@ -149,7 +149,7 @@ static __inline void *
ipi_tlb_context_demap(struct pmap *pm)
{
struct ipi_tlb_args *ita;
- u_int cpus;
+ cpumask_t cpus;
if (smp_cpus == 1)
return (NULL);
@@ -168,7 +168,7 @@ static __inline void *
ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
{
struct ipi_tlb_args *ita;
- u_int cpus;
+ cpumask_t cpus;
if (smp_cpus == 1)
return (NULL);
@@ -187,7 +187,7 @@ static __inline void *
ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
{
struct ipi_tlb_args *ita;
- u_int cpus;
+ cpumask_t cpus;
if (smp_cpus == 1)
return (NULL);
@@ -206,7 +206,7 @@ ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
static __inline void
ipi_wait(void *cookie)
{
- volatile u_int *mask;
+ volatile cpumask_t *mask;
if ((mask = cookie) != NULL) {
atomic_clear_int(mask, PCPU_GET(cpumask));
diff --git a/sys/sun4v/sun4v/mp_machdep.c b/sys/sun4v/sun4v/mp_machdep.c
index a9535e3..961d40c 100644
--- a/sys/sun4v/sun4v/mp_machdep.c
+++ b/sys/sun4v/sun4v/mp_machdep.c
@@ -539,7 +539,7 @@ retry:
}
void
-ipi_selected(u_int icpus, u_int ipi)
+ipi_selected(cpumask_t icpus, u_int ipi)
{
int i, cpu_count;
uint16_t *cpulist;
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index bcb4367..958c74d 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -401,6 +401,9 @@
#endif /* __STDC__ */
#endif /* __GNUC__ || __INTEL_COMPILER */
+#define __GLOBL1(sym) __asm__(".globl " #sym)
+#define __GLOBL(sym) __GLOBL1(sym)
+
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"")
#else
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
index 53cf079..1a9cb5c 100644
--- a/sys/sys/kernel.h
+++ b/sys/sys/kernel.h
@@ -64,8 +64,6 @@ extern int stathz; /* statistics clock's frequency */
extern int profhz; /* profiling clock's frequency */
extern int profprocs; /* number of process's profiling */
extern int ticks;
-extern int timer1hz; /* timer 1 frequency */
-extern int timer2hz; /* timer 2 frequency */
#endif /* _KERNEL */
diff --git a/sys/sys/kerneldump.h b/sys/sys/kerneldump.h
index e3421de..6342f7d 100644
--- a/sys/sys/kerneldump.h
+++ b/sys/sys/kerneldump.h
@@ -71,6 +71,7 @@ struct kerneldumpheader {
#define KERNELDUMP_ARM_VERSION 1
#define KERNELDUMP_I386_VERSION 2
#define KERNELDUMP_IA64_VERSION 1
+#define KERNELDUMP_MIPS_VERSION 1
#define KERNELDUMP_POWERPC_VERSION 1
#define KERNELDUMP_SPARC64_VERSION 1
#define KERNELDUMP_TEXT_VERSION 1
diff --git a/sys/sys/linker_set.h b/sys/sys/linker_set.h
index 5f55beb..2edb55b 100644
--- a/sys/sys/linker_set.h
+++ b/sys/sys/linker_set.h
@@ -45,6 +45,8 @@
*/
#ifdef __GNUCLIKE___SECTION
#define __MAKE_SET(set, sym) \
+ __GLOBL(__CONCAT(__start_set_,set)); \
+ __GLOBL(__CONCAT(__stop_set_,set)); \
static void const * const __set_##set##_sym_##sym \
__section("set_" #set) __used = &sym
#else /* !__GNUCLIKE___SECTION */
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index 5800f80..7088575 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -32,7 +32,6 @@
#ifndef _SYS_MUTEX_H_
#define _SYS_MUTEX_H_
-#ifndef LOCORE
#include <sys/queue.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>
@@ -43,12 +42,6 @@
#include <sys/lockstat.h>
#include <machine/atomic.h>
#include <machine/cpufunc.h>
-#endif /* _KERNEL_ */
-#endif /* !LOCORE */
-
-#include <machine/mutex.h>
-
-#ifdef _KERNEL
/*
* Mutex types and options passed to mtx_init(). MTX_QUIET and MTX_DUPOK
@@ -83,8 +76,6 @@
#endif /* _KERNEL */
-#ifndef LOCORE
-
/*
* XXX: Friendly reminder to fix things in MP code that is presently being
* XXX: worked on.
@@ -137,68 +128,59 @@ void _thread_lock_flags(struct thread *, int, const char *, int);
#define mtx_recurse lock_object.lo_data
-/*
- * We define our machine-independent (unoptimized) mutex micro-operations
- * here, if they are not already defined in the machine-dependent mutex.h
- */
+/* Very simple operations on mtx_lock. */
/* Try to obtain mtx_lock once. */
-#ifndef _obtain_lock
-#define _obtain_lock(mp, tid) \
+#define _mtx_obtain_lock(mp, tid) \
atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid))
-#endif
/* Try to release mtx_lock if it is unrecursed and uncontested. */
-#ifndef _release_lock
-#define _release_lock(mp, tid) \
+#define _mtx_release_lock(mp, tid) \
atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED)
-#endif
/* Release mtx_lock quickly, assuming we own it. */
-#ifndef _release_lock_quick
-#define _release_lock_quick(mp) \
+#define _mtx_release_lock_quick(mp) \
atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED)
-#endif
/*
- * Obtain a sleep lock inline, or call the "hard" function if we can't get it
- * easy.
+ * Full lock operations that are suitable to be inlined in non-debug
+ * kernels. If the lock cannot be acquired or released trivially then
+ * the work is deferred to another function.
*/
-#ifndef _get_sleep_lock
-#define _get_sleep_lock(mp, tid, opts, file, line) do { \
+
+/* Lock a normal mutex. */
+#define __mtx_lock(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
- if (!_obtain_lock((mp), _tid)) \
+ \
+ if (!_mtx_obtain_lock((mp), _tid)) \
_mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \
else \
LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_LOCK_ACQUIRE, \
mp, 0, 0, (file), (line)); \
} while (0)
-#endif
/*
- * Obtain a spin lock inline, or call the "hard" function if we can't get it
- * easy. For spinlocks, we handle recursion inline (it turns out that function
- * calls can be significantly expensive on some architectures).
- * Since spin locks are not _too_ common, inlining this code is not too big
- * a deal.
+ * Lock a spin mutex. For spinlocks, we handle recursion inline (it
+ * turns out that function calls can be significantly expensive on
+ * some architectures). Since spin locks are not _too_ common,
+ * inlining this code is not too big a deal.
*/
-#ifndef _get_spin_lock
#ifdef SMP
-#define _get_spin_lock(mp, tid, opts, file, line) do { \
+#define __mtx_lock_spin(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
+ \
spinlock_enter(); \
- if (!_obtain_lock((mp), _tid)) { \
+ if (!_mtx_obtain_lock((mp), _tid)) { \
if ((mp)->mtx_lock == _tid) \
(mp)->mtx_recurse++; \
- else { \
+ else \
_mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
- } \
} else \
LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(LS_MTX_SPIN_LOCK_ACQUIRE, \
mp, 0, 0, (file), (line)); \
} while (0)
#else /* SMP */
-#define _get_spin_lock(mp, tid, opts, file, line) do { \
+#define __mtx_lock_spin(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
\
spinlock_enter(); \
@@ -206,49 +188,42 @@ void _thread_lock_flags(struct thread *, int, const char *, int);
(mp)->mtx_recurse++; \
else { \
KASSERT((mp)->mtx_lock == MTX_UNOWNED, ("corrupt spinlock")); \
- (mp)->mtx_lock = _tid; \
+ (mp)->mtx_lock = _tid; \
} \
} while (0)
#endif /* SMP */
-#endif
-/*
- * Release a sleep lock inline, or call the "hard" function if we can't do it
- * easy.
- */
-#ifndef _rel_sleep_lock
-#define _rel_sleep_lock(mp, tid, opts, file, line) do { \
+/* Unlock a normal mutex. */
+#define __mtx_unlock(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
\
- if (!_release_lock((mp), _tid)) \
+ if (!_mtx_release_lock((mp), _tid)) \
_mtx_unlock_sleep((mp), (opts), (file), (line)); \
} while (0)
-#endif
/*
- * For spinlocks, we can handle everything inline, as it's pretty simple and
- * a function call would be too expensive (at least on some architectures).
- * Since spin locks are not _too_ common, inlining this code is not too big
- * a deal.
+ * Unlock a spin mutex. For spinlocks, we can handle everything
+ * inline, as it's pretty simple and a function call would be too
+ * expensive (at least on some architectures). Since spin locks are
+ * not _too_ common, inlining this code is not too big a deal.
*
* Since we always perform a spinlock_enter() when attempting to acquire a
* spin lock, we need to always perform a matching spinlock_exit() when
* releasing a spin lock. This includes the recursion cases.
*/
-#ifndef _rel_spin_lock
#ifdef SMP
-#define _rel_spin_lock(mp) do { \
+#define __mtx_unlock_spin(mp) do { \
if (mtx_recursed((mp))) \
(mp)->mtx_recurse--; \
else { \
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_SPIN_UNLOCK_RELEASE, \
mp); \
- _release_lock_quick((mp)); \
+ _mtx_release_lock_quick((mp)); \
} \
spinlock_exit(); \
} while (0)
#else /* SMP */
-#define _rel_spin_lock(mp) do { \
+#define __mtx_unlock_spin(mp) do { \
if (mtx_recursed((mp))) \
(mp)->mtx_recurse--; \
else { \
@@ -259,7 +234,6 @@ void _thread_lock_flags(struct thread *, int, const char *, int);
spinlock_exit(); \
} while (0)
#endif /* SMP */
-#endif
/*
* Exported lock manipulation interface.
@@ -336,13 +310,13 @@ extern struct mtx_pool *mtxpool_sleep;
_mtx_unlock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE)
#else /* LOCK_DEBUG == 0 && !MUTEX_NOINLINE */
#define mtx_lock_flags(m, opts) \
- _get_sleep_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ __mtx_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
#define mtx_unlock_flags(m, opts) \
- _rel_sleep_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ __mtx_unlock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
#define mtx_lock_spin_flags(m, opts) \
- _get_spin_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
+ __mtx_lock_spin((m), curthread, (opts), LOCK_FILE, LOCK_LINE)
#define mtx_unlock_spin_flags(m, opts) \
- _rel_spin_lock((m))
+ __mtx_unlock_spin((m))
#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */
#define mtx_trylock_flags(m, opts) \
@@ -451,5 +425,4 @@ struct mtx_args {
#define MTX_NETWORK_LOCK "network driver"
#endif /* _KERNEL */
-#endif /* !LOCORE */
#endif /* _SYS_MUTEX_H_ */
diff --git a/sys/sys/param.h b/sys/sys/param.h
index ea64e39..a64c77b 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -58,7 +58,7 @@
* in the range 5 to 9.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 900023 /* Master, propagated to newvers */
+#define __FreeBSD_version 900024 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>
diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h
index 75017d6..b029e12 100644
--- a/sys/sys/pcpu.h
+++ b/sys/sys/pcpu.h
@@ -42,11 +42,15 @@
#include <sys/resource.h>
#include <machine/pcpu.h>
+#ifdef _KERNEL
+
/*
* Define a set for pcpu data.
*/
extern uintptr_t *__start_set_pcpu;
+__GLOBL(__start_set_pcpu);
extern uintptr_t *__stop_set_pcpu;
+__GLOBL(__stop_set_pcpu);
/*
* Array of dynamic pcpu base offsets. Indexed by id.
@@ -127,6 +131,8 @@ extern uintptr_t dpcpu_off[];
} \
} while(0)
+#endif /* _KERNEL */
+
/*
* XXXUPS remove as soon as we have per cpu variable
* linker sets and can define rm_queue in _rm_lock.h
diff --git a/sys/sys/taskqueue.h b/sys/sys/taskqueue.h
index bf2e4ee..c7a7b16 100644
--- a/sys/sys/taskqueue.h
+++ b/sys/sys/taskqueue.h
@@ -54,6 +54,8 @@ struct taskqueue *taskqueue_create(const char *name, int mflags,
int taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
const char *name, ...) __printflike(4, 5);
int taskqueue_enqueue(struct taskqueue *queue, struct task *task);
+int taskqueue_cancel(struct taskqueue *queue, struct task *task,
+ u_int *pendp);
void taskqueue_drain(struct taskqueue *queue, struct task *task);
void taskqueue_free(struct taskqueue *queue);
void taskqueue_run(struct taskqueue *queue);
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index ffbe16e..ba2813d 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -582,9 +582,7 @@ ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
* block to be kept. -1 indicates the entire
* block so we need not calculate the index.
*/
- factor = 1;
- for (i = SINGLE; i < level; i++)
- factor *= NINDIR(fs);
+ factor = lbn_offset(fs, level);
last = lastbn;
if (lastbn > 0)
last /= factor;
diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c
index ca4ea0b..9e347cf 100644
--- a/sys/ufs/ffs/ffs_softdep.c
+++ b/sys/ufs/ffs/ffs_softdep.c
@@ -2270,7 +2270,6 @@ journal_mount(mp, fs, cred)
int error;
int i;
- mp->mnt_kern_flag |= MNTK_SUJ;
error = softdep_journal_lookup(mp, &vp);
if (error != 0) {
printf("Failed to find journal. Use tunefs to create one\n");
@@ -2295,20 +2294,26 @@ journal_mount(mp, fs, cred)
}
jblocks->jb_low = jblocks->jb_free / 3; /* Reserve 33%. */
jblocks->jb_min = jblocks->jb_free / 10; /* Suspend at 10%. */
- /*
- * Only validate the journal contents if the filesystem is clean,
- * otherwise we write the logs but they'll never be used. If the
- * filesystem was still dirty when we mounted it the journal is
- * invalid and a new journal can only be valid if it starts from a
- * clean mount.
- */
- if (fs->fs_clean) {
- DIP_SET(ip, i_modrev, fs->fs_mtime);
- ip->i_flags |= IN_MODIFIED;
- ffs_update(vp, 1);
- }
VFSTOUFS(mp)->softdep_jblocks = jblocks;
out:
+ if (error == 0) {
+ MNT_ILOCK(mp);
+ mp->mnt_kern_flag |= MNTK_SUJ;
+ MNT_IUNLOCK(mp);
+ /*
+ * Only validate the journal contents if the
+ * filesystem is clean, otherwise we write the logs
+ * but they'll never be used. If the filesystem was
+ * still dirty when we mounted it the journal is
+ * invalid and a new journal can only be valid if it
+ * starts from a clean mount.
+ */
+ if (fs->fs_clean) {
+ DIP_SET(ip, i_modrev, fs->fs_mtime);
+ ip->i_flags |= IN_MODIFIED;
+ ffs_update(vp, 1);
+ }
+ }
vput(vp);
return (error);
}
@@ -5265,7 +5270,7 @@ softdep_setup_freeblocks(ip, length, flags)
if (delay)
WORKLIST_INSERT(&bp->b_dep, &freeblks->fb_list);
else if (needj)
- freeblks->fb_state |= DEPCOMPLETE | COMPLETE;
+ freeblks->fb_state |= COMPLETE;
/*
* Because the file length has been truncated to zero, any
* pending block allocation dependency structures associated
@@ -5327,8 +5332,9 @@ restart:
if (inodedep_lookup(mp, ip->i_number, 0, &inodedep) != 0)
(void) free_inodedep(inodedep);
- if (delay) {
+ if (delay || needj)
freeblks->fb_state |= DEPCOMPLETE;
+ if (delay) {
/*
* If the inode with zeroed block pointers is now on disk
* we can start freeing blocks. Add freeblks to the worklist
@@ -5339,6 +5345,8 @@ restart:
if ((freeblks->fb_state & ALLCOMPLETE) == ALLCOMPLETE)
add_to_worklist(&freeblks->fb_list, 1);
}
+ if (needj && LIST_EMPTY(&freeblks->fb_jfreeblkhd))
+ needj = 0;
FREE_LOCK(&lk);
/*
@@ -5488,7 +5496,7 @@ cancel_allocdirect(adphead, adp, freeblks, delay)
newblk = (struct newblk *)adp;
/*
* If the journal hasn't been written the jnewblk must be passed
- * to the call to ffs_freeblk that reclaims the space. We accomplish
+ * to the call to ffs_blkfree that reclaims the space. We accomplish
* this by linking the journal dependency into the freework to be
* freed when freework_freeblock() is called. If the journal has
* been written we can simply reclaim the journal space when the
@@ -6016,11 +6024,11 @@ handle_complete_freeblocks(freeblks)
vput(vp);
}
-#ifdef INVARIANTS
- if (freeblks->fb_chkcnt != 0 &&
- ((fs->fs_flags & FS_UNCLEAN) == 0 || (flags & LK_NOWAIT) != 0))
- printf("handle_workitem_freeblocks: block count\n");
-#endif /* INVARIANTS */
+ KASSERT(freeblks->fb_chkcnt == 0 ||
+ ((fs->fs_flags & FS_UNCLEAN) != 0 && (flags & LK_NOWAIT) == 0),
+ ("handle_workitem_freeblocks: inode %ju block count %jd\n",
+ (uintmax_t)freeblks->fb_previousinum,
+ (intmax_t)freeblks->fb_chkcnt));
ACQUIRE_LOCK(&lk);
/*
@@ -6075,9 +6083,7 @@ indir_trunc(freework, dbn, lbn)
fs_pendingblocks = 0;
freedeps = 0;
needj = UFSTOVFS(ump)->mnt_kern_flag & MNTK_SUJ;
- lbnadd = 1;
- for (i = level; i > 0; i--)
- lbnadd *= NINDIR(fs);
+ lbnadd = lbn_offset(fs, level);
/*
* Get buffer of block pointers to be freed. This routine is not
* called until the zero'ed inode has been written, so it is safe
@@ -6273,7 +6279,7 @@ cancel_allocindir(aip, inodedep, freeblks)
/*
* If the journal hasn't been written the jnewblk must be passed
- * to the call to ffs_freeblk that reclaims the space. We accomplish
+ * to the call to ffs_blkfree that reclaims the space. We accomplish
* this by linking the journal dependency into the indirdep to be
* freed when indir_trunc() is called. If the journal has already
* been written we can simply reclaim the journal space when the
diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h
index 42c4cfe..ba98ed3 100644
--- a/sys/ufs/ffs/fs.h
+++ b/sys/ufs/ffs/fs.h
@@ -607,6 +607,11 @@ struct cg {
: (fragroundup(fs, blkoff(fs, (size)))))
/*
+ * Number of indirects in a filesystem block.
+ */
+#define NINDIR(fs) ((fs)->fs_nindir)
+
+/*
* Indirect lbns are aligned on NDADDR addresses where single indirects
* are the negated address of the lowest lbn reachable, double indirects
* are this lbn - 1 and triple indirects are this lbn - 2. This yields
@@ -631,6 +636,17 @@ lbn_level(ufs_lbn_t lbn)
}
return (-1);
}
+
+static inline ufs_lbn_t
+lbn_offset(struct fs *fs, int level)
+{
+ ufs_lbn_t res;
+
+ for (res = 1; level > 0; level--)
+ res *= NINDIR(fs);
+ return (res);
+}
+
/*
* Number of inodes in a secondary storage block/fragment.
*/
@@ -638,11 +654,6 @@ lbn_level(ufs_lbn_t lbn)
#define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift)
/*
- * Number of indirects in a filesystem block.
- */
-#define NINDIR(fs) ((fs)->fs_nindir)
-
-/*
* Softdep journal record format.
*/
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index 9c8bc1b..794c2f3 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -61,8 +61,6 @@ __FBSDID("$FreeBSD$");
#include <sys/conf.h>
#include <sys/acl.h>
-#include <machine/mutex.h>
-
#include <security/mac/mac_framework.h>
#include <sys/file.h> /* XXX */
diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c
index 40c317d..b35ae10 100644
--- a/sys/vm/vm_map.c
+++ b/sys/vm/vm_map.c
@@ -3338,7 +3338,8 @@ Retry:
if (grow_amount > stack_entry->avail_ssize)
grow_amount = stack_entry->avail_ssize;
if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > stacklim)) {
- grow_amount = stacklim - ctob(vm->vm_ssize);
+ grow_amount = trunc_page((vm_size_t)stacklim) -
+ ctob(vm->vm_ssize);
}
/* If we would blow our VMEM resource limit, no go */
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index d778c99..32b90e6 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -359,7 +359,8 @@ vm_page_startup(vm_offset_t vaddr)
bzero((void *)mapped, end - new_end);
uma_startup((void *)mapped, boot_pages);
-#if defined(__amd64__) || defined(__i386__) || defined(__arm__)
+#if defined(__amd64__) || defined(__i386__) || defined(__arm__) || \
+ defined(__mips__)
/*
* Allocate a bitmap to indicate that a random physical page
* needs to be included in a minidump.
diff --git a/sys/vm/vm_reserv.c b/sys/vm/vm_reserv.c
index 423bb31..f5f44f7 100644
--- a/sys/vm/vm_reserv.c
+++ b/sys/vm/vm_reserv.c
@@ -194,7 +194,7 @@ sysctl_vm_reserv_partpopq(SYSCTL_HANDLER_ARGS)
}
mtx_unlock(&vm_page_queue_free_mtx);
sbuf_printf(&sbuf, "%5d: %6dK, %6d\n", level,
- unused_pages * (PAGE_SIZE / 1024), counter);
+ unused_pages * ((int)PAGE_SIZE / 1024), counter);
}
error = sbuf_finish(&sbuf);
sbuf_delete(&sbuf);
diff --git a/sys/amd64/acpica/OsdEnvironment.c b/sys/x86/acpica/OsdEnvironment.c
index fb01a3f..a35a3e0 100644
--- a/sys/amd64/acpica/OsdEnvironment.c
+++ b/sys/x86/acpica/OsdEnvironment.c
@@ -28,9 +28,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/*
- * 6.1 : Environmental support
- */
#include <sys/types.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
@@ -39,33 +36,56 @@ __FBSDID("$FreeBSD$");
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/actables.h>
-static u_long amd64_acpi_root;
+static u_long acpi_root_phys;
-SYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &amd64_acpi_root, 0,
- "The physical address of the RSDP");
+SYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &acpi_root_phys, 0,
+ "The physical address of the RSDP");
ACPI_STATUS
AcpiOsInitialize(void)
{
- return(0);
+
+ return (AE_OK);
}
ACPI_STATUS
AcpiOsTerminate(void)
{
- return(0);
+
+ return (AE_OK);
+}
+
+static u_long
+acpi_get_root_from_loader(void)
+{
+ long acpi_root;
+
+ if (resource_long_value("acpi", 0, "rsdp", &acpi_root) == 0)
+ return (acpi_root);
+
+ return (0);
+}
+
+static u_long
+acpi_get_root_from_memory(void)
+{
+ ACPI_SIZE acpi_root;
+
+ if (ACPI_SUCCESS(AcpiFindRootPointer(&acpi_root)))
+ return (acpi_root);
+
+ return (0);
}
ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer(void)
{
- u_long ptr;
- if (amd64_acpi_root == 0 &&
- (resource_long_value("acpi", 0, "rsdp", (long *)&ptr) == 0 ||
- AcpiFindRootPointer((ACPI_SIZE *)&ptr) == AE_OK) &&
- ptr != 0)
- amd64_acpi_root = ptr;
+ if (acpi_root_phys == 0) {
+ acpi_root_phys = acpi_get_root_from_loader();
+ if (acpi_root_phys == 0)
+ acpi_root_phys = acpi_get_root_from_memory();
+ }
- return (amd64_acpi_root);
+ return (acpi_root_phys);
}
diff --git a/sys/x86/acpica/acpi_apm.c b/sys/x86/acpica/acpi_apm.c
new file mode 100644
index 0000000..02be6e0
--- /dev/null
+++ b/sys/x86/acpica/acpi_apm.c
@@ -0,0 +1,489 @@
+/*-
+ * Copyright (c) 2001 Mitsuru IWASAKI
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/poll.h>
+#include <sys/uio.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
+
+#include <dev/acpica/acpivar.h>
+#include <dev/acpica/acpiio.h>
+
+#include <machine/apm_bios.h>
+
+/*
+ * APM driver emulation
+ */
+
+#define APM_UNKNOWN 0xff
+
+static int apm_active;
+static struct clonedevs *apm_clones;
+
+MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation");
+
+static d_open_t apmopen;
+static d_close_t apmclose;
+static d_write_t apmwrite;
+static d_ioctl_t apmioctl;
+static d_poll_t apmpoll;
+static d_kqfilter_t apmkqfilter;
+static void apmreadfiltdetach(struct knote *kn);
+static int apmreadfilt(struct knote *kn, long hint);
+static struct filterops apm_readfiltops = {
+ .f_isfd = 1,
+ .f_detach = apmreadfiltdetach,
+ .f_event = apmreadfilt,
+};
+
+static struct cdevsw apm_cdevsw = {
+ .d_version = D_VERSION,
+ .d_flags = D_TRACKCLOSE | D_NEEDMINOR,
+ .d_open = apmopen,
+ .d_close = apmclose,
+ .d_write = apmwrite,
+ .d_ioctl = apmioctl,
+ .d_poll = apmpoll,
+ .d_name = "apm",
+ .d_kqfilter = apmkqfilter
+};
+
+static int
+acpi_capm_convert_battstate(struct acpi_battinfo *battp)
+{
+ int state;
+
+ state = APM_UNKNOWN;
+
+ if (battp->state & ACPI_BATT_STAT_DISCHARG) {
+ if (battp->cap >= 50)
+ state = 0; /* high */
+ else
+ state = 1; /* low */
+ }
+ if (battp->state & ACPI_BATT_STAT_CRITICAL)
+ state = 2; /* critical */
+ if (battp->state & ACPI_BATT_STAT_CHARGING)
+ state = 3; /* charging */
+
+ /* If still unknown, determine it based on the battery capacity. */
+ if (state == APM_UNKNOWN) {
+ if (battp->cap >= 50)
+ state = 0; /* high */
+ else
+ state = 1; /* low */
+ }
+
+ return (state);
+}
+
+static int
+acpi_capm_convert_battflags(struct acpi_battinfo *battp)
+{
+ int flags;
+
+ flags = 0;
+
+ if (battp->cap >= 50)
+ flags |= APM_BATT_HIGH;
+ else {
+ if (battp->state & ACPI_BATT_STAT_CRITICAL)
+ flags |= APM_BATT_CRITICAL;
+ else
+ flags |= APM_BATT_LOW;
+ }
+ if (battp->state & ACPI_BATT_STAT_CHARGING)
+ flags |= APM_BATT_CHARGING;
+ if (battp->state == ACPI_BATT_STAT_NOT_PRESENT)
+ flags = APM_BATT_NOT_PRESENT;
+
+ return (flags);
+}
+
+static int
+acpi_capm_get_info(apm_info_t aip)
+{
+ int acline;
+ struct acpi_battinfo batt;
+
+ aip->ai_infoversion = 1;
+ aip->ai_major = 1;
+ aip->ai_minor = 2;
+ aip->ai_status = apm_active;
+ aip->ai_capabilities= 0xff00; /* unknown */
+
+ if (acpi_acad_get_acline(&acline))
+ aip->ai_acline = APM_UNKNOWN; /* unknown */
+ else
+ aip->ai_acline = acline; /* on/off */
+
+ if (acpi_battery_get_battinfo(NULL, &batt) != 0) {
+ aip->ai_batt_stat = APM_UNKNOWN;
+ aip->ai_batt_life = APM_UNKNOWN;
+ aip->ai_batt_time = -1; /* unknown */
+ aip->ai_batteries = ~0U; /* unknown */
+ } else {
+ aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
+ aip->ai_batt_life = batt.cap;
+ aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
+ aip->ai_batteries = acpi_battery_get_units();
+ }
+
+ return (0);
+}
+
+static int
+acpi_capm_get_pwstatus(apm_pwstatus_t app)
+{
+ device_t dev;
+ int acline, unit, error;
+ struct acpi_battinfo batt;
+
+ if (app->ap_device != PMDV_ALLDEV &&
+ (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
+ return (1);
+
+ if (app->ap_device == PMDV_ALLDEV)
+ error = acpi_battery_get_battinfo(NULL, &batt);
+ else {
+ unit = app->ap_device - PMDV_BATT0;
+ dev = devclass_get_device(devclass_find("battery"), unit);
+ if (dev != NULL)
+ error = acpi_battery_get_battinfo(dev, &batt);
+ else
+ error = ENXIO;
+ }
+ if (error)
+ return (1);
+
+ app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
+ app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
+ app->ap_batt_life = batt.cap;
+ app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
+
+ if (acpi_acad_get_acline(&acline))
+ app->ap_acline = APM_UNKNOWN;
+ else
+ app->ap_acline = acline; /* on/off */
+
+ return (0);
+}
+
+/* Create single-use devices for /dev/apm and /dev/apmctl. */
+static void
+apm_clone(void *arg, struct ucred *cred, char *name, int namelen,
+ struct cdev **dev)
+{
+ int ctl_dev, unit;
+
+ if (*dev != NULL)
+ return;
+ if (strcmp(name, "apmctl") == 0)
+ ctl_dev = TRUE;
+ else if (strcmp(name, "apm") == 0)
+ ctl_dev = FALSE;
+ else
+ return;
+
+ /* Always create a new device and unit number. */
+ unit = -1;
+ if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) {
+ if (ctl_dev) {
+ *dev = make_dev(&apm_cdevsw, unit,
+ UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit);
+ } else {
+ *dev = make_dev(&apm_cdevsw, unit,
+ UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit);
+ }
+ if (*dev != NULL) {
+ dev_ref(*dev);
+ (*dev)->si_flags |= SI_CHEAPCLONE;
+ }
+ }
+}
+
+/* Create a struct for tracking per-device suspend notification. */
+static struct apm_clone_data *
+apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc)
+{
+ struct apm_clone_data *clone;
+
+ clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK);
+ clone->cdev = dev;
+ clone->acpi_sc = acpi_sc;
+ clone->notify_status = APM_EV_NONE;
+ bzero(&clone->sel_read, sizeof(clone->sel_read));
+ knlist_init_mtx(&clone->sel_read.si_note, &acpi_mutex);
+
+ /*
+ * The acpi device is always managed by devd(8) and is considered
+ * writable (i.e., ack is required to allow suspend to proceed.)
+ */
+ if (strcmp("acpi", devtoname(dev)) == 0)
+ clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE;
+ else
+ clone->flags = ACPI_EVF_NONE;
+
+ ACPI_LOCK(acpi);
+ STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries);
+ ACPI_UNLOCK(acpi);
+ return (clone);
+}
+
+static int
+apmopen(struct cdev *dev, int flag, int fmt, struct thread *td)
+{
+ struct acpi_softc *acpi_sc;
+ struct apm_clone_data *clone;
+
+ acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
+ clone = apm_create_clone(dev, acpi_sc);
+ dev->si_drv1 = clone;
+
+ /* If the device is opened for write, record that. */
+ if ((flag & FWRITE) != 0)
+ clone->flags |= ACPI_EVF_WRITE;
+
+ return (0);
+}
+
+static int
+apmclose(struct cdev *dev, int flag, int fmt, struct thread *td)
+{
+ struct apm_clone_data *clone;
+ struct acpi_softc *acpi_sc;
+
+ clone = dev->si_drv1;
+ acpi_sc = clone->acpi_sc;
+
+ /* We are about to lose a reference so check if suspend should occur */
+ if (acpi_sc->acpi_next_sstate != 0 &&
+ clone->notify_status != APM_EV_ACKED)
+ acpi_AckSleepState(clone, 0);
+
+ /* Remove this clone's data from the list and free it. */
+ ACPI_LOCK(acpi);
+ STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries);
+ knlist_destroy(&clone->sel_read.si_note);
+ ACPI_UNLOCK(acpi);
+ free(clone, M_APMDEV);
+ destroy_dev_sched(dev);
+ return (0);
+}
+
+static int
+apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+{
+ int error;
+ struct apm_clone_data *clone;
+ struct acpi_softc *acpi_sc;
+ struct apm_info info;
+ struct apm_event_info *ev_info;
+ apm_info_old_t aiop;
+
+ error = 0;
+ clone = dev->si_drv1;
+ acpi_sc = clone->acpi_sc;
+
+ switch (cmd) {
+ case APMIO_SUSPEND:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ if (acpi_sc->acpi_next_sstate == 0) {
+ if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) {
+ error = acpi_ReqSleepState(acpi_sc,
+ acpi_sc->acpi_suspend_sx);
+ } else {
+ printf(
+ "power off via apm suspend not supported\n");
+ error = ENXIO;
+ }
+ } else
+ error = acpi_AckSleepState(clone, 0);
+ break;
+ case APMIO_STANDBY:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ if (acpi_sc->acpi_next_sstate == 0) {
+ if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) {
+ error = acpi_ReqSleepState(acpi_sc,
+ acpi_sc->acpi_standby_sx);
+ } else {
+ printf(
+ "power off via apm standby not supported\n");
+ error = ENXIO;
+ }
+ } else
+ error = acpi_AckSleepState(clone, 0);
+ break;
+ case APMIO_NEXTEVENT:
+ printf("apm nextevent start\n");
+ ACPI_LOCK(acpi);
+ if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status ==
+ APM_EV_NONE) {
+ ev_info = (struct apm_event_info *)addr;
+ if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3)
+ ev_info->type = PMEV_STANDBYREQ;
+ else
+ ev_info->type = PMEV_SUSPENDREQ;
+ ev_info->index = 0;
+ clone->notify_status = APM_EV_NOTIFIED;
+ printf("apm event returning %d\n", ev_info->type);
+ } else
+ error = EAGAIN;
+ ACPI_UNLOCK(acpi);
+ break;
+ case APMIO_GETINFO_OLD:
+ if (acpi_capm_get_info(&info))
+ error = ENXIO;
+ aiop = (apm_info_old_t)addr;
+ aiop->ai_major = info.ai_major;
+ aiop->ai_minor = info.ai_minor;
+ aiop->ai_acline = info.ai_acline;
+ aiop->ai_batt_stat = info.ai_batt_stat;
+ aiop->ai_batt_life = info.ai_batt_life;
+ aiop->ai_status = info.ai_status;
+ break;
+ case APMIO_GETINFO:
+ if (acpi_capm_get_info((apm_info_t)addr))
+ error = ENXIO;
+ break;
+ case APMIO_GETPWSTATUS:
+ if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
+ error = ENXIO;
+ break;
+ case APMIO_ENABLE:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ apm_active = 1;
+ break;
+ case APMIO_DISABLE:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ apm_active = 0;
+ break;
+ case APMIO_HALTCPU:
+ break;
+ case APMIO_NOTHALTCPU:
+ break;
+ case APMIO_DISPLAY:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ break;
+ case APMIO_BIOS:
+ if ((flag & FWRITE) == 0)
+ return (EPERM);
+ bzero(addr, sizeof(struct apm_bios_arg));
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return (error);
+}
+
+static int
+apmwrite(struct cdev *dev, struct uio *uio, int ioflag)
+{
+ return (uio->uio_resid);
+}
+
+static int
+apmpoll(struct cdev *dev, int events, struct thread *td)
+{
+ struct apm_clone_data *clone;
+ int revents;
+
+ revents = 0;
+ ACPI_LOCK(acpi);
+ clone = dev->si_drv1;
+ if (clone->acpi_sc->acpi_next_sstate)
+ revents |= events & (POLLIN | POLLRDNORM);
+ else
+ selrecord(td, &clone->sel_read);
+ ACPI_UNLOCK(acpi);
+ return (revents);
+}
+
+static int
+apmkqfilter(struct cdev *dev, struct knote *kn)
+{
+ struct apm_clone_data *clone;
+
+ ACPI_LOCK(acpi);
+ clone = dev->si_drv1;
+ kn->kn_hook = clone;
+ kn->kn_fop = &apm_readfiltops;
+ knlist_add(&clone->sel_read.si_note, kn, 0);
+ ACPI_UNLOCK(acpi);
+ return (0);
+}
+
+static void
+apmreadfiltdetach(struct knote *kn)
+{
+ struct apm_clone_data *clone;
+
+ ACPI_LOCK(acpi);
+ clone = kn->kn_hook;
+ knlist_remove(&clone->sel_read.si_note, kn, 0);
+ ACPI_UNLOCK(acpi);
+}
+
+static int
+apmreadfilt(struct knote *kn, long hint)
+{
+ struct apm_clone_data *clone;
+ int sleeping;
+
+ ACPI_LOCK(acpi);
+ clone = kn->kn_hook;
+ sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0;
+ ACPI_UNLOCK(acpi);
+ return (sleeping);
+}
+
+void
+acpi_apm_init(struct acpi_softc *sc)
+{
+
+ /* Create a clone for /dev/acpi also. */
+ STAILQ_INIT(&sc->apm_cdevs);
+ sc->acpi_clone = apm_create_clone(sc->acpi_dev_t, sc);
+ clone_setup(&apm_clones);
+ EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000);
+}
diff --git a/sys/i386/acpica/madt.c b/sys/x86/acpica/madt.c
index f153696..13bbb55 100644
--- a/sys/i386/acpica/madt.c
+++ b/sys/x86/acpica/madt.c
@@ -95,7 +95,6 @@ static struct apic_enumerator madt_enumerator = {
madt_setup_io
};
-
/*
* Look for an ACPI Multiple APIC Description Table ("APIC")
*/
@@ -204,7 +203,7 @@ madt_register(void *dummy __unused)
apic_register_enumerator(&madt_enumerator);
}
-SYSINIT(madt_register, SI_SUB_CPU - 1, SI_ORDER_SECOND, madt_register, NULL);
+SYSINIT(madt_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, madt_register, NULL);
/*
* Call the handler routine for each entry in the MADT table.
diff --git a/sys/x86/cpufreq/hwpstate.c b/sys/x86/cpufreq/hwpstate.c
index 3790b76..18659d7 100644
--- a/sys/x86/cpufreq/hwpstate.c
+++ b/sys/x86/cpufreq/hwpstate.c
@@ -118,8 +118,9 @@ static int hwpstate_get_info_from_msr(device_t dev);
static int hwpstate_goto_pstate(device_t dev, int pstate_id);
static int hwpstate_verbose = 0;
-SYSCTL_INT(_debug, OID_AUTO, hwpstate_verbose, CTLFLAG_RDTUN,
+SYSCTL_INT(_debug, OID_AUTO, hwpstate_verbose, CTLFLAG_RW | CTLFLAG_TUN,
&hwpstate_verbose, 0, "Debug hwpstate");
+TUNABLE_INT("debug.hwpstate_verbose", &hwpstate_verbose);
static device_method_t hwpstate_methods[] = {
/* Device interface */
diff --git a/sys/x86/include/apm_bios.h b/sys/x86/include/apm_bios.h
new file mode 100644
index 0000000..05bef86
--- /dev/null
+++ b/sys/x86/include/apm_bios.h
@@ -0,0 +1,264 @@
+/*-
+ * APM (Advanced Power Management) BIOS Device Driver
+ *
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ *
+ * This software may be used, modified, copied, and distributed, in
+ * both source and binary form provided that the above copyright and
+ * these terms are retained. Under no circumstances is the author
+ * responsible for the proper functioning of this software, nor does
+ * the author assume any responsibility for damages incurred with its
+ * use.
+ *
+ * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _X86_APM_BIOS_H_
+#define _X86_APM_BIOS_H_
+
+#ifndef _KERNEL
+#include <sys/types.h>
+#endif
+#include <sys/ioccom.h>
+
+/* BIOS id */
+#define APM_BIOS 0x53
+#define APM_INT 0x15
+
+/* APM flags */
+#define APM_16BIT_SUPPORT 0x01
+#define APM_32BIT_SUPPORT 0x02
+#define APM_CPUIDLE_SLOW 0x04
+#define APM_DISABLED 0x08
+#define APM_DISENGAGED 0x10
+
+/* APM initializer physical address */
+#define APM_OURADDR 0x00080000
+
+/* APM functions */
+#define APM_INSTCHECK 0x00
+#define APM_REALCONNECT 0x01
+#define APM_PROT16CONNECT 0x02
+#define APM_PROT32CONNECT 0x03
+#define APM_DISCONNECT 0x04
+#define APM_CPUIDLE 0x05
+#define APM_CPUBUSY 0x06
+#define APM_SETPWSTATE 0x07
+#define APM_ENABLEDISABLEPM 0x08
+#define APM_RESTOREDEFAULT 0x09
+#define APM_GETPWSTATUS 0x0a
+#define APM_GETPMEVENT 0x0b
+#define APM_GETPWSTATE 0x0c
+#define APM_ENABLEDISABLEDPM 0x0d
+#define APM_DRVVERSION 0x0e
+#define APM_ENGAGEDISENGAGEPM 0x0f
+#define APM_GETCAPABILITIES 0x10
+#define APM_RESUMETIMER 0x11
+#define APM_RESUMEONRING 0x12
+#define APM_TIMERREQUESTS 0x13
+#define APM_OEMFUNC 0x80
+
+/* error code */
+#define APME_OK 0x00
+#define APME_PMDISABLED 0x01
+#define APME_REALESTABLISHED 0x02
+#define APME_NOTCONNECTED 0x03
+#define APME_PROT16ESTABLISHED 0x05
+#define APME_PROT16NOTSUPPORTED 0x06
+#define APME_PROT32ESTABLISHED 0x07
+#define APME_PROT32NOTDUPPORTED 0x08
+#define APME_UNKNOWNDEVICEID 0x09
+#define APME_OUTOFRANGE 0x0a
+#define APME_NOTENGAGED 0x0b
+#define APME_CANTENTERSTATE 0x60
+#define APME_NOPMEVENT 0x80
+#define APME_NOAPMPRESENT 0x86
+
+
+/* device code */
+#define PMDV_APMBIOS 0x0000
+#define PMDV_ALLDEV 0x0001
+#define PMDV_DISP0 0x0100
+#define PMDV_DISP1 0x0101
+#define PMDV_DISPALL 0x01ff
+#define PMDV_2NDSTORAGE0 0x0200
+#define PMDV_2NDSTORAGE1 0x0201
+#define PMDV_2NDSTORAGE2 0x0202
+#define PMDV_2NDSTORAGE3 0x0203
+#define PMDV_PARALLEL0 0x0300
+#define PMDV_PARALLEL1 0x0301
+#define PMDV_SERIAL0 0x0400
+#define PMDV_SERIAL1 0x0401
+#define PMDV_SERIAL2 0x0402
+#define PMDV_SERIAL3 0x0403
+#define PMDV_SERIAL4 0x0404
+#define PMDV_SERIAL5 0x0405
+#define PMDV_SERIAL6 0x0406
+#define PMDV_SERIAL7 0x0407
+#define PMDV_NET0 0x0500
+#define PMDV_NET1 0x0501
+#define PMDV_NET2 0x0502
+#define PMDV_NET3 0x0503
+#define PMDV_PCMCIA0 0x0600
+#define PMDV_PCMCIA1 0x0601
+#define PMDV_PCMCIA2 0x0602
+#define PMDV_PCMCIA3 0x0603
+/* 0x0700 - 0x7fff Reserved */
+#define PMDV_BATT_BASE 0x8000
+#define PMDV_BATT0 0x8001
+#define PMDV_BATT1 0x8002
+#define PMDV_BATT_ALL 0x80ff
+/* 0x8100 - 0xdfff Reserved */
+/* 0xe000 - 0xefff OEM-defined power device IDs */
+/* 0xf000 - 0xffff Reserved */
+
+/* Power state */
+#define PMST_APMENABLED 0x0000
+#define PMST_STANDBY 0x0001
+#define PMST_SUSPEND 0x0002
+#define PMST_OFF 0x0003
+#define PMST_LASTREQNOTIFY 0x0004
+#define PMST_LASTREQREJECT 0x0005
+/* 0x0006 - 0x001f Reserved system states */
+/* 0x0020 - 0x003f OEM-defined system states */
+/* 0x0040 - 0x007f OEM-defined device states */
+/* 0x0080 - 0xffff Reserved device states */
+
+#if !defined(ASSEMBLER) && !defined(INITIALIZER)
+
+/* C definitions */
+struct apmhook {
+ struct apmhook *ah_next;
+ int (*ah_fun)(void *ah_arg);
+ void *ah_arg;
+ const char *ah_name;
+ int ah_order;
+};
+#define APM_HOOK_NONE (-1)
+#define APM_HOOK_SUSPEND 0
+#define APM_HOOK_RESUME 1
+#define NAPM_HOOK 2
+
+#ifdef _KERNEL
+
+void apm_suspend(int state);
+struct apmhook *apm_hook_establish (int apmh, struct apmhook *);
+void apm_hook_disestablish (int apmh, struct apmhook *);
+void apm_cpu_idle(void);
+void apm_cpu_busy(void);
+
+#endif
+
+#endif /* !ASSEMBLER && !INITIALIZER */
+
+#define APM_MIN_ORDER 0x00
+#define APM_MID_ORDER 0x80
+#define APM_MAX_ORDER 0xff
+
+/* power management event code */
+#define PMEV_NOEVENT 0x0000
+#define PMEV_STANDBYREQ 0x0001
+#define PMEV_SUSPENDREQ 0x0002
+#define PMEV_NORMRESUME 0x0003
+#define PMEV_CRITRESUME 0x0004
+#define PMEV_BATTERYLOW 0x0005
+#define PMEV_POWERSTATECHANGE 0x0006
+#define PMEV_UPDATETIME 0x0007
+#define PMEV_CRITSUSPEND 0x0008
+#define PMEV_USERSTANDBYREQ 0x0009
+#define PMEV_USERSUSPENDREQ 0x000a
+#define PMEV_STANDBYRESUME 0x000b
+#define PMEV_CAPABILITIESCHANGE 0x000c
+/* 0x000d - 0x00ff Reserved system events */
+/* 0x0100 - 0x01ff Reserved device events */
+/* 0x0200 - 0x02ff OEM-defined APM events */
+/* 0x0300 - 0xffff Reserved */
+#define PMEV_DEFAULT 0xffffffff /* used for customization */
+
+#if !defined(ASSEMBLER) && !defined(INITIALIZER)
+
+/*
+ * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This
+ * is for backward compatibility with old executables.
+ */
+typedef struct apm_info_old {
+ u_int ai_major; /* APM major version */
+ u_int ai_minor; /* APM minor version */
+ u_int ai_acline; /* AC line status */
+ u_int ai_batt_stat; /* Battery status */
+ u_int ai_batt_life; /* Remaining battery life */
+ u_int ai_status; /* Status of APM support (enabled/disabled) */
+} *apm_info_old_t;
+
+/*
+ * Structure returned by the APMIO_GETINFO ioctl.
+ *
+ * In the comments below, the parenthesized numbers indicate the minimum
+ * value of ai_infoversion for which each field is valid.
+ */
+typedef struct apm_info {
+ u_int ai_infoversion; /* Indicates which fields are valid */
+ u_int ai_major; /* APM major version (0) */
+ u_int ai_minor; /* APM minor version (0) */
+ u_int ai_acline; /* AC line status (0) */
+ u_int ai_batt_stat; /* Battery status (0) */
+ u_int ai_batt_life; /* Remaining battery life in percent (0) */
+ int ai_batt_time; /* Remaining battery time in seconds (0) */
+ u_int ai_status; /* True if enabled (0) */
+ u_int ai_batteries; /* Number of batteries (1) */
+ u_int ai_capabilities;/* APM Capabilities (1) */
+ u_int ai_spare[6]; /* For future expansion */
+} *apm_info_t;
+
+/* Battery flag */
+#define APM_BATT_HIGH 0x01
+#define APM_BATT_LOW 0x02
+#define APM_BATT_CRITICAL 0x04
+#define APM_BATT_CHARGING 0x08
+#define APM_BATT_NOT_PRESENT 0x10
+#define APM_BATT_NO_SYSTEM 0x80
+
+typedef struct apm_pwstatus {
+ u_int ap_device; /* Device code of battery */
+ u_int ap_acline; /* AC line status (0) */
+ u_int ap_batt_stat; /* Battery status (0) */
+ u_int ap_batt_flag; /* Battery flag (0) */
+ u_int ap_batt_life; /* Remaining battery life in percent (0) */
+ int ap_batt_time; /* Remaining battery time in seconds (0) */
+} *apm_pwstatus_t;
+
+struct apm_bios_arg {
+ uint32_t eax;
+ uint32_t ebx;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t esi;
+ uint32_t edi;
+};
+
+struct apm_event_info {
+ u_int type;
+ u_int index;
+ u_int spare[8];
+};
+
+#define APMIO_SUSPEND _IO('P', 1)
+#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old)
+#define APMIO_ENABLE _IO('P', 5)
+#define APMIO_DISABLE _IO('P', 6)
+#define APMIO_HALTCPU _IO('P', 7)
+#define APMIO_NOTHALTCPU _IO('P', 8)
+#define APMIO_DISPLAY _IOW('P', 9, int)
+#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg)
+#define APMIO_GETINFO _IOR('P', 11, struct apm_info)
+#define APMIO_STANDBY _IO('P', 12)
+#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus)
+/* for /dev/apmctl */
+#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info)
+#define APMIO_REJECTLASTREQ _IO('P', 101)
+
+#endif /* !ASSEMBLER && !INITIALIZER */
+
+#endif /* !_X86_APM_BIOS_H_ */
diff --git a/sys/amd64/include/mptable.h b/sys/x86/include/mptable.h
index 451d9ce..451d9ce 100644
--- a/sys/amd64/include/mptable.h
+++ b/sys/x86/include/mptable.h
diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c
index 63a6843..7f8e583 100644
--- a/sys/x86/x86/local_apic.c
+++ b/sys/x86/x86/local_apic.c
@@ -324,16 +324,21 @@ lapic_create(u_int apic_id, int boot_cpu)
void
lapic_dump(const char* str)
{
+ uint32_t maxlvt;
+ maxlvt = (lapic->version & APIC_VER_MAXLVT) >> MAXLVTSHIFT;
printf("cpu%d %s:\n", PCPU_GET(cpuid), str);
printf(" ID: 0x%08x VER: 0x%08x LDR: 0x%08x DFR: 0x%08x\n",
lapic->id, lapic->version, lapic->ldr, lapic->dfr);
printf(" lint0: 0x%08x lint1: 0x%08x TPR: 0x%08x SVR: 0x%08x\n",
lapic->lvt_lint0, lapic->lvt_lint1, lapic->tpr, lapic->svr);
- printf(" timer: 0x%08x therm: 0x%08x err: 0x%08x pmc: 0x%08x\n",
- lapic->lvt_timer, lapic->lvt_thermal, lapic->lvt_error,
- lapic->lvt_pcint);
- printf(" cmci: 0x%08x\n", lapic->lvt_cmci);
+ printf(" timer: 0x%08x therm: 0x%08x err: 0x%08x",
+ lapic->lvt_timer, lapic->lvt_thermal, lapic->lvt_error);
+ if (maxlvt >= LVT_PMC)
+ printf(" pmc: 0x%08x", lapic->lvt_pcint);
+ printf("\n");
+ if (maxlvt >= LVT_CMCI)
+ printf(" cmci: 0x%08x\n", lapic->lvt_cmci);
}
void
@@ -1280,7 +1285,7 @@ apic_init(void *dummy __unused)
if (resource_disabled("apic", 0))
return;
- /* First, probe all the enumerators to find the best match. */
+ /* Probe all the enumerators to find the best match. */
best_enum = NULL;
best = 0;
SLIST_FOREACH(enumerator, &enumerators, apic_next) {
@@ -1316,13 +1321,12 @@ apic_init(void *dummy __unused)
}
#endif
- /* Second, probe the CPU's in the system. */
+ /* Probe the CPU's in the system. */
retval = best_enum->apic_probe_cpus();
if (retval != 0)
printf("%s: Failed to probe CPUs: returned %d\n",
best_enum->apic_name, retval);
-#ifdef __amd64__
}
SYSINIT(apic_init, SI_SUB_TUNABLES - 1, SI_ORDER_SECOND, apic_init, NULL);
@@ -1337,19 +1341,14 @@ apic_setup_local(void *dummy __unused)
if (best_enum == NULL)
return;
-#endif
- /* Third, initialize the local APIC. */
+
+ /* Initialize the local APIC. */
retval = best_enum->apic_setup_local();
if (retval != 0)
printf("%s: Failed to setup the local APIC: returned %d\n",
best_enum->apic_name, retval);
}
-#ifdef __amd64__
-SYSINIT(apic_setup_local, SI_SUB_CPU, SI_ORDER_SECOND, apic_setup_local,
- NULL);
-#else
-SYSINIT(apic_init, SI_SUB_CPU, SI_ORDER_SECOND, apic_init, NULL);
-#endif
+SYSINIT(apic_setup_local, SI_SUB_CPU, SI_ORDER_SECOND, apic_setup_local, NULL);
/*
* Setup the I/O APICs.
diff --git a/sys/x86/x86/mptable.c b/sys/x86/x86/mptable.c
index cad83a2..4b240a6 100644
--- a/sys/x86/x86/mptable.c
+++ b/sys/x86/x86/mptable.c
@@ -39,11 +39,11 @@ __FBSDID("$FreeBSD$");
#include <vm/pmap.h>
#include <x86/apicreg.h>
+#include <x86/mptable.h>
#include <machine/frame.h>
#include <machine/intr_machdep.h>
#include <machine/apicvar.h>
#include <machine/md_var.h>
-#include <machine/mptable.h>
#include <machine/specialreg.h>
#include <dev/pci/pcivar.h>
@@ -389,7 +389,7 @@ mptable_register(void *dummy __unused)
apic_register_enumerator(&mptable_enumerator);
}
-SYSINIT(mptable_register, SI_SUB_CPU - 1, SI_ORDER_FIRST, mptable_register,
+SYSINIT(mptable_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, mptable_register,
NULL);
/*
diff --git a/sys/x86/x86/mptable_pci.c b/sys/x86/x86/mptable_pci.c
index 47a666d..398444c 100644
--- a/sys/x86/x86/mptable_pci.c
+++ b/sys/x86/x86/mptable_pci.c
@@ -44,8 +44,8 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcib_private.h>
+#include <x86/mptable.h>
#include <machine/legacyvar.h>
-#include <machine/mptable.h>
#include <machine/pci_cfgreg.h>
#include "pcib_if.h"
diff --git a/tools/build/mk/OptionalObsoleteFiles.inc b/tools/build/mk/OptionalObsoleteFiles.inc
index 6a9d448..4ce9968 100644
--- a/tools/build/mk/OptionalObsoleteFiles.inc
+++ b/tools/build/mk/OptionalObsoleteFiles.inc
@@ -1790,6 +1790,7 @@ OLD_FILES+=usr/share/man/man8/tftp-proxy.8.gz
.if ${MK_PKGTOOLS} == no
OLD_FILES+=etc/periodic/daily/490.status-pkg-changes
+OLD_FILES+=etc/periodic/security/460.chkportsum
OLD_FILES+=etc/periodic/weekly/400.status-pkg
OLD_FILES+=usr/include/pkg.h
OLD_FILES+=usr/lib/libpkg.a
diff --git a/tools/regression/acltools/tools-nfs4.test b/tools/regression/acltools/tools-nfs4.test
index 3e41add..72826fb 100644
--- a/tools/regression/acltools/tools-nfs4.test
+++ b/tools/regression/acltools/tools-nfs4.test
@@ -527,7 +527,6 @@ $ setfacl -a0 owner@:r:allow,group@:w:deny,group@:wx:allow ddd
$ ls -ld ddd | cut -d' ' -f1
> dr----x---+
-# XXX: This one is fishy. Shouldn't it be "dr---wx---+"?
$ rmdir ddd
$ mkdir ddd
$ chmod 0 ddd
diff --git a/tools/regression/bin/Makefile b/tools/regression/bin/Makefile
index e0e3ea3..1dcdbb3 100644
--- a/tools/regression/bin/Makefile
+++ b/tools/regression/bin/Makefile
@@ -1,5 +1,5 @@
# $FreeBSD$
-SUBDIR= date mv pax sh
+SUBDIR= date mv pax sh test
.include <bsd.subdir.mk>
diff --git a/tools/regression/bin/test/Makefile b/tools/regression/bin/test/Makefile
new file mode 100644
index 0000000..2c9ca59
--- /dev/null
+++ b/tools/regression/bin/test/Makefile
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+all:
+ sh regress.sh
diff --git a/bin/test/TEST.sh b/tools/regression/bin/test/regress.sh
index 6dd16bc..716c260 100644
--- a/bin/test/TEST.sh
+++ b/tools/regression/bin/test/regress.sh
@@ -30,44 +30,29 @@
#
# $FreeBSD$
-# force a specified test program, e.g. `env test=/bin/test sh TEST.sh'
+# force a specified test program, e.g. `env test=/bin/test sh regress.sh'
: ${test=test}
-ERROR=0 FAILED=0
-
t ()
{
# $1 -> exit code
# $2 -> $test expression
- echo -n "$1: $test $2 "
-
+ count=$((count+1))
# check for syntax errors
syntax="`eval $test $2 2>&1`"
- if test -z "$syntax"; then
-
- case $1 in
- 0) if eval $test $2; then echo " OK"; else failed;fi;;
- 1) if eval $test $2; then failed; else echo " OK";fi;;
- esac
-
+ ret=$?
+ if test -n "$syntax"; then
+ printf "not ok %s - (syntax error)\n" "$count $2"
+ elif [ "$ret" != "$1" ]; then
+ printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
else
- error
+ printf "ok %s\n" "$count $2"
fi
}
-error ()
-{
- echo ""; echo " $syntax"
- ERROR=`expr $ERROR + 1`
-}
-
-failed ()
-{
- echo ""; echo " failed"
- FAILED=`expr $FAILED + 1`
-}
-
+count=0
+echo "1..94"
t 0 'b = b'
t 1 'b != b'
@@ -172,6 +157,3 @@ t 1 '-z y -o y = "#" -o y = x'
t 0 '0 -ne 0 -o ! -f /'
t 0 '1 -ne 0 -o ! -f /etc/passwd'
t 1 '0 -ne 0 -o ! -f /etc/passwd'
-
-echo ""
-echo "Syntax errors: $ERROR Failed: $FAILED"
diff --git a/tools/regression/bin/test/regress.t b/tools/regression/bin/test/regress.t
new file mode 100644
index 0000000..c36d834
--- /dev/null
+++ b/tools/regression/bin/test/regress.t
@@ -0,0 +1,6 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+sh regress.sh
diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh
index b7fc9fd..0ecf847 100644
--- a/tools/tools/nanobsd/nanobsd.sh
+++ b/tools/tools/nanobsd/nanobsd.sh
@@ -75,6 +75,9 @@ CONF_WORLD=' '
# Kernel config file to use
NANO_KERNEL=GENERIC
+# Kernel modules to build; default is none
+NANO_MODULES=
+
# Customize commands.
NANO_CUSTOMIZE=""
@@ -150,6 +153,12 @@ NANO_LABEL=""
NANO_ARCH=`uname -p`
+# Directory to populate /cfg from
+NANO_CFGDIR=""
+
+# Directory to populate /data from
+NANO_DATADIR=""
+
#######################################################################
#
# The functions which do the real work.
@@ -173,6 +182,7 @@ make_conf_build ( ) (
echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD}
echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD}
+ echo "_WITHOUT_SRCCONF=t" >> ${NANO_MAKE_CONF_BUILD}
)
build_world ( ) (
@@ -189,19 +199,26 @@ build_kernel ( ) (
pprint 2 "build kernel ($NANO_KERNEL)"
pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
+ (
if [ -f ${NANO_KERNEL} ] ; then
- cp ${NANO_KERNEL} ${NANO_SRC}/sys/${NANO_ARCH}/conf
+ kernconfdir=$(realpath $(dirname ${NANO_KERNEL}))
+ kernconf=$(basename ${NANO_KERNEL})
+ else
+ kernconf=${NANO_KERNEL}
fi
- (cd ${NANO_SRC};
+ cd ${NANO_SRC};
# unset these just in case to avoid compiler complaints
# when cross-building
unset TARGET_CPUTYPE
unset TARGET_BIG_ENDIAN
+ # Note: We intentionally build all modules, not only the ones in
+ # NANO_MODULES so the built world can be reused by multiple images.
env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \
- __MAKE_CONF=${NANO_MAKE_CONF_BUILD} KERNCONF=`basename ${NANO_KERNEL}` \
- > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
- )
+ __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \
+ ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \
+ KERNCONF=${kernconf}
+ ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
)
clean_world ( ) (
@@ -228,6 +245,7 @@ make_conf_install ( ) (
echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL}
echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL}
+ echo "_WITHOUT_SRCCONF=t" >> ${NANO_MAKE_CONF_INSTALL}
)
install_world ( ) (
@@ -258,14 +276,25 @@ install_etc ( ) (
)
install_kernel ( ) (
- pprint 2 "install kernel"
+ pprint 2 "install kernel ($NANO_KERNEL)"
pprint 3 "log: ${NANO_OBJ}/_.ik"
+ (
+ if [ -f ${NANO_KERNEL} ] ; then
+ kernconfdir=$(realpath $(dirname ${NANO_KERNEL}))
+ kernconf=$(basename ${NANO_KERNEL})
+ else
+ kernconf=${NANO_KERNEL}
+ fi
+
cd ${NANO_SRC}
env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \
DESTDIR=${NANO_WORLDDIR} \
- __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} KERNCONF=`basename ${NANO_KERNEL}` \
- > ${NANO_OBJ}/_.ik 2>&1
+ __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
+ ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \
+ KERNCONF=${kernconf} \
+ MODULES_OVERRIDE="${NANO_MODULES}"
+ ) > ${NANO_OBJ}/_.ik 2>&1
)
run_customize() (
@@ -276,7 +305,7 @@ run_customize() (
pprint 2 "customize \"$c\""
pprint 3 "log: ${NANO_OBJ}/_.cust.$c"
pprint 4 "`type $c`"
- ( $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
+ ( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
done
)
@@ -288,7 +317,7 @@ run_late_customize() (
pprint 2 "late customize \"$c\""
pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c"
pprint 4 "`type $c`"
- ( $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
+ ( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
done
)
@@ -890,6 +919,9 @@ else
fi
if $do_kernel ; then
+ if ! $do_world ; then
+ make_conf_build
+ fi
build_kernel
else
pprint 2 "Skipping buildkernel (as instructed)"
diff --git a/usr.bin/calendar/calendars/calendar.freebsd b/usr.bin/calendar/calendars/calendar.freebsd
index 4c553aa..e5118da 100644
--- a/usr.bin/calendar/calendars/calendar.freebsd
+++ b/usr.bin/calendar/calendars/calendar.freebsd
@@ -7,8 +7,8 @@
#ifndef _calendar_freebsd_
#define _calendar_freebsd_
-01/01 Alexander Langer <alex@FreeBSD.org> born in Duesseldorf, Nordrhein-Westfalen, Germany, 1981
01/01 Dimitry Andric <dim@FreeBSD.org> born in Utrecht, the Netherlands, 1969
+01/01 Alexander Langer <alex@FreeBSD.org> born in Duesseldorf, Nordrhein-Westfalen, Germany, 1981
01/02 Ion-Mihai "IOnut" Tetcu <itetcu@FreeBSD.org> born in Bucharest, Romania, 1980
01/02 Patrick Li <pat@FreeBSD.org> born in Beijing, People's Republic of China, 1985
01/03 Tetsurou Okazaki <okazaki@FreeBSD.org> born in Mobara, Chiba, Japan, 1972
@@ -24,13 +24,13 @@
01/16 Vanilla I. Shu <vanilla@FreeBSD.org> born in Taipei, Taiwan, Republic of China, 1978
01/18 Dejan Lesjak <lesi@FreeBSD.org> born in Ljubljana, Slovenia, Yugoslavia, 1977
01/19 Marshall Kirk McKusick <mckusick@FreeBSD.org> born in Wilmington, Delaware, United States, 1954
-01/19 Marcelo S. Araujo <araujo@FreeBSD.org> born in Joinville, Santa Catarina, Brazil, 1981
01/19 Ruslan Ermilov <ru@FreeBSD.org> born in Simferopol, USSR, 1974
+01/19 Marcelo S. Araujo <araujo@FreeBSD.org> born in Joinville, Santa Catarina, Brazil, 1981
01/20 Poul-Henning Kamp <phk@FreeBSD.org> born in Korsoer, Denmark, 1966
01/22 Johann Visagie <wjv@FreeBSD.org> born in Cape Town, South Africa, 1970
01/23 Hideyuki KURASHINA <rushani@FreeBSD.org> born in Niigata, Japan, 1982
-01/24 Matteo Riondato <matteo@FreeBSD.org> born in Padova, Italy, 1986
01/24 Fabien Thomas <fabient@FreeBSD.org> born in Avignon, France, 1971
+01/24 Matteo Riondato <matteo@FreeBSD.org> born in Padova, Italy, 1986
01/25 Bernd Walter <ticso@FreeBSD.org> born in Moers, Nordrhein-Westfalen, Germany, 1974
01/26 Andrew Gallatin <gallatin@FreeBSD.org> born in Buffalo, New York, United States, 1970
01/27 Nick Sayer <nsayer@FreeBSD.org> born in San Diego, California, United States, 1968
@@ -41,21 +41,21 @@
02/01 Paul Saab <ps@FreeBSD.org> born in Champaign-Urbana, Illinois, United States, 1978
02/01 Martin Wilke <miwi@FreeBSD.org> born in Ludwigsfelde, Brandenburg, Germany, 1980
02/01 Christian Brueffer <brueffer@FreeBSD.org> born in Gronau, Nordrhein-Westfalen, Germany, 1982
-02/01 Steven Kreuzer <skreuzer@FreeBSD.org> born in Oceanside, New York, 1982
+02/01 Steven Kreuzer <skreuzer@FreeBSD.org> born in Oceanside, New York, United States, 1982
02/01 Juli Mallett <jmallett@FreeBSD.org> born in Washington, Pennsylvania, United States, 1985
-02/02 Michael W Lucas <mwlucas@FreeBSD.org> born in Detroit, Michigan, United States, 1967
02/02 Diomidis D. Spinellis <dds@FreeBSD.org> born in Athens, Greece, 1967
+02/02 Michael W Lucas <mwlucas@FreeBSD.org> born in Detroit, Michigan, United States, 1967
02/02 Yoichi Nakayama <yoichi@FreeBSD.org> born in Tsu, Mie, Japan, 1976
02/05 Frank Laszlo <laszlof@FreeBSD.org> born in Howell, Michigan, United States, 1983
02/10 David Greenman <dg@FreeBSD.org> born in Portland, Oregon, United States, 1968
02/10 Paul Richards <paul@FreeBSD.org> born in Ammanford, Carmarthenshire, United Kingdom, 1968
02/10 Simon Barner <barner@FreeBSD.org> born in Rosenheim, Bayern, Germany, 1980
02/13 Jesper Skriver <jesper@FreeBSD.org> born in Aarhus, Denmark, 1975
+02/13 Steve Wills <swills@FreeBSD.org> born in Lynchburg, Virginia, United States, 1975
02/13 Andrey Slusar <anray@FreeBSD.org> born in Odessa, USSR, 1979
02/13 David W. Chapman Jr. <dwcjr@FreeBSD.org> born in Bethel, Connecticut, United States, 1981
-02/13 Steve Wills <swills@FreeBSD.org> born in Lynchburg, Virginia, United States, 1975
-02/14 Erwin Lansing <erwin@FreeBSD.org> born in 's-Hertogenbosch, the Netherlands, 1975
02/14 Manolis Kiagias <manolis@FreeBSD.org> born in Chania, Greece, 1970
+02/14 Erwin Lansing <erwin@FreeBSD.org> born in 's-Hertogenbosch, the Netherlands, 1975
02/14 Martin Blapp <mbr@FreeBSD.org> born in Olten, Switzerland, 1976
02/19 Murray Stokely <murray@FreeBSD.org> born in Jacksonville, Florida, United States, 1979
02/20 Anders Nordby <anders@FreeBSD.org> born in Oslo, Norway, 1976
@@ -92,10 +92,10 @@
03/17 Alexander Motin <mav@FreeBSD.org> born in Simferopol, Ukraine, 1979
03/18 Koop Mast <kwm@FreeBSD.org> born in Dokkum, the Netherlands, 1981
03/19 Mikhail Teterin <mi@FreeBSD.org> born in Kyiv, Ukraine, 1972
+03/20 Joseph S. Atkinson <jsa@FreeBSD.org> born in Batesville, Arkansas, United States, 1977
+03/20 Henrik Brix Andersen <brix@FreeBSD.org> born in Aarhus, Denmark, 1978
03/20 MANTANI Nobutaka <nobutaka@FreeBSD.org> born in Hiroshima, Japan, 1978
03/20 Cameron Grant <cg@FreeBSD.org> died in Hemel Hempstead, United Kingdom, 2005
-03/20 Henrik Brix Andersen <brix@FreeBSD.org> born in Aarhus, Denmark, 1978
-03/20 Joseph S. Atkinson <jsa@FreeBSD.org> born in Batesville, Arkansas, United States, 1977
03/22 Brad Davis <brd@FreeBSD.org> born in Farmington, New Mexico, United States, 1983
03/23 Daniel C. Sobral <dcs@FreeBSD.org> born in Brasilia, Distrito Federal, Brazil, 1971
03/23 Benno Rice <benno@FreeBSD.org> born in Adelaide, South Australia, Australia, 1977
@@ -112,7 +112,7 @@
04/03 Hellmuth Michaelis <hm@FreeBSD.org> born in Kiel, Schleswig-Holstein, Germany, 1958
04/03 Tong Liu <nemoliu@FreeBSD.org> born in Beijing, People's Republic of China, 1981
04/03 Gabor Pali <pgj@FreeBSD.org> born in Kunhegyes, Hungary, 1982
-04/05 Stacey Son <sson@FreeBSD.org> born in Burley, Idaho, United States. 1967
+04/05 Stacey Son <sson@FreeBSD.org> born in Burley, Idaho, United States, 1967
04/07 Edward Tomasz Napierala <trasz@FreeBSD.org> born in Wolsztyn, Poland, 1981
04/08 Jordan K. Hubbard <jkh@FreeBSD.org> born in Honolulu, Hawaii, United States, 1963
04/09 Ceri Davies <ceri@FreeBSD.org> born in Haverfordwest, Pembrokeshire, United Kingdom, 1976
@@ -141,9 +141,9 @@
05/11 Jesus Rodriguez <jesusr@FreeBSD.org> born in Barcelona, Spain, 1972
05/11 Roman Kurakin <rik@FreeBSD.org> born in Moscow, USSR, 1979
05/13 Pete Fritchman <petef@FreeBSD.org> born in Lansdale, Pennsylvania, United States, 1983
-05/14 Bruce Cran <brucec@FreeBSD.org> born in Cambridge, United Kingdom, 1981
05/14 Tatsumi Hosokawa <hosokawa@FreeBSD.org> born in Tokyo, Japan, 1968
05/14 Shigeyuku Fukushima <shige@FreeBSD.org> born in Osaka, Japan, 1974
+05/14 Bruce Cran <brucec@FreeBSD.org> born in Cambridge, United Kingdom, 1981
05/16 Johann Kois <jkois@FreeBSD.org> born in Wolfsberg, Austria, 1975
05/16 Marcus Alves Grando <mnag@FreeBSD.org> born in Florianopolis, Santa Catarina, Brazil, 1979
05/17 Thomas Abthorpe <tabthorpe@FreeBSD.org> born in Port Arthur, Ontario, Canada, 1968
@@ -151,30 +151,31 @@
05/19 Ian Dowse <iedowse@FreeBSD.org> born in Dublin, Ireland, 1975
05/21 Kris Kennaway <kris@FreeBSD.org> born in Winnipeg, Manitoba, Canada, 1978
05/22 Clive Tong-I Lin <clive@FreeBSD.org> born in Changhua, Taiwan, Republic of China, 1978
-05/22 Michael Bushkov <bushman@FreeBSD.org> born in Rostov-on-Don, Russia, 1985
-05/22 Rui Paulo <rpaulo@FreeBSD.org>, born in Evora, Portugal, 1986
+05/22 Michael Bushkov <bushman@FreeBSD.org> born in Rostov-on-Don, Russian Federation, 1985
+05/22 Rui Paulo <rpaulo@FreeBSD.org> born in Evora, Portugal, 1986
05/23 Munechika Sumikawa <sumikawa@FreeBSD.org> born in Osaka, Osaka, Japan, 1972
05/24 Duncan McLennan Barclay <dmlb@FreeBSD.org> born in London, Middlesex, United Kingdom, 1970
05/24 Oliver Lehmann <oliver@FreeBSD.org> born in Karlsburg, Germany, 1981
-05/25 Roman Divacky <rdivacky@FreeBSD.org> born in Brno, Czech Republic, 1983
05/25 Tom Rhodes <trhodes@FreeBSD.org> born in Ellwood City, Pennsylvania, United States, 1981
+05/25 Roman Divacky <rdivacky@FreeBSD.org> born in Brno, Czech Republic, 1983
05/26 Jim Pirzyk <pirzyk@FreeBSD.org> born in Chicago, Illinois, United States, 1968
05/27 Ollivier Robert <roberto@FreeBSD.org> born in Paris, France, 1967
05/29 Wilko Bulte <wilko@FreeBSD.org> born in Arnhem, the Netherlands, 1965
05/29 Seigo Tanimura <tanimura@FreeBSD.org> born in Kitakyushu, Fukuoka, Japan, 1976
05/31 Ville Skytta <scop@FreeBSD.org> born in Helsinki, Finland, 1974
06/02 Jean-Marc Zucconi <jmz@FreeBSD.org> born in Pontarlier, France, 1954
-06/02 Alexander Botero-Lowry <alexbl@FreeBSD.org> born in Austin, TX, USA, 1986
+06/02 Alexander Botero-Lowry <alexbl@FreeBSD.org> born in Austin, Texas, United States, 1986
06/03 CHOI Junho <cjh@FreeBSD.org> born in Seoul, Korea, 1974
-06/03 Wesley Shields <wxs@FreeBSD.org> born in Binghamton, NY, USA, 1981
+06/03 Wesley Shields <wxs@FreeBSD.org> born in Binghamton, New York, United States, 1981
06/04 Julian Elischer <julian@FreeBSD.org> born in Perth, Australia, 1959
-06/04 Jason Evans <jasone@FreeBSD.org> born in Greeley, Colorado, United States, 1973
06/04 Justin Gibbs <gibbs@FreeBSD.org> born in San Pedro, California, United States, 1973
+06/04 Jason Evans <jasone@FreeBSD.org> born in Greeley, Colorado, United States, 1973
06/04 Thomas Moestl <tmm@FreeBSD.org> born in Braunschweig, Niedersachsen, Germany, 1980
+06/04 Zack Kirsch <zack@FreeBSD.org> born in Memphis, Tennessee, United States, 1982
06/06 Sergei Kolobov <sergei@FreeBSD.org> born in Karpinsk, Russian Federation, 1972
06/06 Alan Eldridge <alane@FreeBSD.org> died in Denver, Colorado, 2003
-06/07 Benjamin Close <benjsc@FreeBSD.org> born in Adelaide, Australia, 1978
06/07 Jimmy Olgeni <olgeni@FreeBSD.org> born in Milano, Italy, 1976
+06/07 Benjamin Close <benjsc@FreeBSD.org> born in Adelaide, Australia, 1978
06/17 Tilman Linneweh <arved@FreeBSD.org> born in Weinheim, Baden-Wuertemberg, Germany, 1978
06/18 Li-Wen Hsu <lwhsu@FreeBSD.org> born in Taipei, Taiwan, Republic of China, 1984
06/18 Roman Bogorodskiy <novel@FreeBSD.org> born in Saratov, Russian Federation, 1986
@@ -229,15 +230,15 @@
08/07 Jonathan Mini <mini@FreeBSD.org> born in San Mateo, California, United States, 1979
08/10 Peter Pentchev <roam@FreeBSD.org> born in Sofia, Bulgaria, 1977
08/12 Joe Marcus Clarke <marcus@FreeBSD.org> born in Lakeland, Florida, United States, 1976
-08/12 Max Brazhnikov <makc@FreeBSD.org> born in Leningradskaya, Russia, 1979
+08/12 Max Brazhnikov <makc@FreeBSD.org> born in Leningradskaya, Russian Federation, 1979
08/14 Stefan Esser <se@FreeBSD.org> born in Cologne, Nordrhein-Westfalen, Germany, 1961
08/17 Olivier Houchard <cognet@FreeBSD.org> born in Nancy, France, 1980
-08/19 Pav Lucistnik <pav@FreeBSD.org> born in Kutna Hora, Czech Republic, 1980
08/19 Chin-San Huang <chinsan@FreeBSD.org> born in Yi-Lan, Taiwan, Republic of China, 1979
+08/19 Pav Lucistnik <pav@FreeBSD.org> born in Kutna Hora, Czech Republic, 1980
08/20 Michael Heffner <mikeh@FreeBSD.org> born in Cleona, Pennsylvania, United States, 1981
08/24 Mark Linimon <linimon@FreeBSD.org> born in Houston, Texas, United States, 1955
-08/25 Jean Milanez Melo <jmelo@FreeBSD.org> born in Divinopolis, Minas Gerais, Brazil, 1982
08/25 Beech Rintoul <beech@FreeBSD.org> born in Oakland, California, United States, 1952
+08/25 Jean Milanez Melo <jmelo@FreeBSD.org> born in Divinopolis, Minas Gerais, Brazil, 1982
08/26 Dima Ruban <dima@FreeBSD.org> born in Nalchik, USSR, 1970
08/26 Marc Fonvieille <blackend@FreeBSD.org> born in Avignon, France, 1972
08/26 Herve Quiroz <hq@FreeBSD.org> born in Aix-en-Provence, France, 1977
@@ -257,8 +258,8 @@
09/09 Yoshio Mita <mita@FreeBSD.org> born in Hiroshima, Japan, 1972
09/10 Wesley R. Peters <wes@FreeBSD.org> born in Hartford, Alabama, United States, 1961
09/12 Weongyo Jeong <weongyo@FreeBSD.org> born in Haman, Korea, 1980
-09/12 William C. Fumerola II <billf@FreeBSD.org> born in Detroit, Michigan, United States, 1981
09/12 Benedict Christopher Reuschling <bcr@FreeBSD.org> born in Darmstadt, Germany, 1981
+09/12 William C. Fumerola II <billf@FreeBSD.org> born in Detroit, Michigan, United States, 1981
09/15 Dima Panov <fluffy@FreeBSD.org> born in Khabarovsk, Russian Federation, 1978
09/17 Maxim Bolotin <mb@FreeBSD.org> born in Rostov-on-Don, Russian Federation, 1976
09/18 Matthew Fleming <mdf@FreeBSD.org> born in Cleveland, Ohio, United States, 1975
@@ -272,7 +273,7 @@
10/02 Beat Gaetzi <beat@FreeBSD.org> born in Zurich, Switzerland, 1980
10/05 Hiroki Sato <hrs@FreeBSD.org> born in Yamagata, Japan, 1977
10/05 Chris Costello <chris@FreeBSD.org> born in Houston, Texas, United States, 1985
-10/09 Stefan Walter <stefan@FreeBSD.org> born in Werne, Nordrhein-Westfalen, 1978
+10/09 Stefan Walter <stefan@FreeBSD.org> born in Werne, Nordrhein-Westfalen, Germany, 1978
10/12 Pawel Jakub Dawidek <pjd@FreeBSD.org> born in Radzyn Podlaski, Poland, 1980
10/15 Maxim Konovalov <maxim@FreeBSD.org> born in Khabarovsk, USSR, 1973
10/16 Remko Lodder <remko@FreeBSD.org> born in Rotterdam, the Netherlands, 1983
@@ -287,10 +288,10 @@
10/22 Jean-Sebastien Pedron <dumbbell@FreeBSD.org> born in Redon, Ille-et-Vilaine, France, 1980
10/23 Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org> born in Brasilia, Distrito Federal, Brazil, 1976
10/25 Eric Melville <eric@FreeBSD.org> born in Los Gatos, California, United States, 1980
-10/26 Philip M. Gollucci <pgollucci@FreeBSD.org> born in Silver Spring, Maryland, United States, 1979
+10/26 Philip M. Gollucci <pgollucci@FreeBSD.org> born in Silver Spring, Maryland, United States, 1979
10/27 Takanori Watanabe <takawata@FreeBSD.org> born in Numazu, Shizuoka, Japan, 1972
11/05 M. Warner Losh <imp@FreeBSD.org> born in Kansas City, Kansas, United States, 1966
-11/09 Coleman Kane <cokane@FreeBSD.org> born in Cincinnati, OH, United States, 1980
+11/09 Coleman Kane <cokane@FreeBSD.org> born in Cincinnati, Ohio, United States, 1980
11/09 Antoine Brodin <antoine@FreeBSD.org> born in Bagnolet, France, 1981
11/10 Gregory Neil Shapiro <gshapiro@FreeBSD.org> born in Providence, Rhode Island, United States, 1970
11/13 John Baldwin <jhb@FreeBSD.org> born in Stuart, Virginia, United States, 1977
@@ -310,7 +311,7 @@
11/28 Stanislav Sedov <stas@FreeBSD.org> born in Chelyabinsk, USSR, 1985
12/01 Hajimu Umemoto <ume@FreeBSD.org> born in Nara, Japan, 1961
12/01 Alexey Dokuchaev <danfe@FreeBSD.org> born in Magadan, USSR, 1980
-12/02 Ermal Luçi <eri@FreeBSD.org> born in Tirane, Albania, 1980
+12/02 Ermal Luçi <eri@FreeBSD.org> born in Tirane, Albania, 1980
12/03 Diane Bruce <db@FreeBSD.org> born in Ottawa, Ontario, Canada, 1952
12/05 Ivan Voras <ivoras@FreeBSD.org> born in Slavonski Brod, Croatia, 1981
12/06 Stefan Farfeleder <stefanf@FreeBSD.org> born in Wien, Austria, 1980
diff --git a/usr.bin/lex/Makefile b/usr.bin/lex/Makefile
index e16568f..947eba1 100644
--- a/usr.bin/lex/Makefile
+++ b/usr.bin/lex/Makefile
@@ -44,7 +44,7 @@ test: check
check: $(PROG)
./$(PROG) $(LFLAGS) -t $(COMPRESSION) $(.CURDIR)/scan.l \
| sed s,\"$(.CURDIR)/scan.l",\"scan.l", \
- | diff $(.CURDIR)/initscan.c -
+ | diff -I '\$$FreeBS[D]:.*\$$' $(.CURDIR)/initscan.c -
@echo "Check successful"
.include <bsd.prog.mk>
diff --git a/usr.bin/lex/initscan.c b/usr.bin/lex/initscan.c
index 59c81f7..7620c52 100644
--- a/usr.bin/lex/initscan.c
+++ b/usr.bin/lex/initscan.c
@@ -3,9 +3,15 @@
/* Scanner skeleton version:
* $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $
+ * $FreeBSD$
*/
+
+#if defined(__FreeBSD__)
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#else
+#define __unused
+#define __dead2
+#endif
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
@@ -243,7 +249,7 @@ YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
-static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )) __unused;
static void yy_flex_free YY_PROTO(( void * ));
#define yy_new_buffer yy_create_buffer
@@ -273,7 +279,7 @@ extern char *yytext;
static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
-static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] )) __dead2;
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -1273,11 +1279,7 @@ char *yytext;
*/
/* $Header: /home/daffy/u0/vern/flex/RCS/scan.l,v 2.56 95/04/24 12:17:19 vern Exp $ */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
+/* $FreeBSD$ */
#include "flexdef.h"
#include "parse.h"
@@ -1336,7 +1338,7 @@ static const char rcsid[] =
#define OPTION 17
#define LINEDIR 18
-#line 1333 "scan.c"
+#line 1342 "scan.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -1490,7 +1492,7 @@ YY_DECL
char *yy_cp, *yy_bp;
int yy_act;
-#line 94 "scan.l"
+#line 95 "scan.l"
static int bracelevel, didadef, indented_code;
static int doing_rule_action = false;
@@ -1501,7 +1503,7 @@ YY_DECL
Char nmdef[MAXLINE], myesc();
-#line 1498 "scan.c"
+#line 1507 "scan.c"
if ( yy_init )
{
@@ -1588,32 +1590,32 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 105 "scan.l"
+#line 106 "scan.l"
indented_code = true; BEGIN(CODEBLOCK);
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 106 "scan.l"
+#line 107 "scan.l"
ACTION_ECHO; yy_push_state( COMMENT );
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 107 "scan.l"
+#line 108 "scan.l"
yy_push_state( LINEDIR );
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 108 "scan.l"
+#line 109 "scan.l"
return SCDECL;
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 109 "scan.l"
+#line 110 "scan.l"
return XSCDECL;
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 110 "scan.l"
+#line 111 "scan.l"
{
++linenum;
line_directive_out( (FILE *) 0, 1 );
@@ -1623,12 +1625,12 @@ YY_RULE_SETUP
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 117 "scan.l"
+#line 118 "scan.l"
/* discard */
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 119 "scan.l"
+#line 120 "scan.l"
{
sectnum = 2;
bracelevel = 0;
@@ -1640,37 +1642,37 @@ YY_RULE_SETUP
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 128 "scan.l"
+#line 129 "scan.l"
yytext_is_array = false; ++linenum;
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 129 "scan.l"
+#line 130 "scan.l"
yytext_is_array = true; ++linenum;
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 131 "scan.l"
+#line 132 "scan.l"
BEGIN(OPTION); return OPTION_OP;
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 133 "scan.l"
+#line 134 "scan.l"
++linenum; /* ignore */
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 134 "scan.l"
+#line 135 "scan.l"
++linenum; /* ignore */
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 136 "scan.l"
+#line 137 "scan.l"
synerr( _( "unrecognized '%' directive" ) );
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 138 "scan.l"
+#line 139 "scan.l"
{
strcpy( nmstr, yytext );
didadef = false;
@@ -1679,56 +1681,56 @@ YY_RULE_SETUP
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 144 "scan.l"
+#line 145 "scan.l"
RETURNNAME;
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 145 "scan.l"
+#line 146 "scan.l"
++linenum; /* allows blank lines in section 1 */
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 146 "scan.l"
+#line 147 "scan.l"
ACTION_ECHO; ++linenum; /* maybe end of comment line */
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 151 "scan.l"
+#line 152 "scan.l"
ACTION_ECHO; yy_pop_state();
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 152 "scan.l"
+#line 153 "scan.l"
ACTION_ECHO;
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 153 "scan.l"
+#line 154 "scan.l"
ACTION_ECHO;
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 154 "scan.l"
+#line 155 "scan.l"
++linenum; ACTION_ECHO;
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 158 "scan.l"
+#line 159 "scan.l"
yy_pop_state();
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 159 "scan.l"
+#line 160 "scan.l"
linenum = myctoi( yytext );
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 161 "scan.l"
+#line 162 "scan.l"
{
flex_free( (void *) infilename );
infilename = copy_string( yytext + 1 );
@@ -1737,24 +1739,24 @@ YY_RULE_SETUP
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 166 "scan.l"
+#line 167 "scan.l"
/* ignore spurious characters */
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 170 "scan.l"
+#line 171 "scan.l"
++linenum; BEGIN(INITIAL);
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 172 "scan.l"
+#line 173 "scan.l"
ACTION_ECHO;
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 174 "scan.l"
+#line 175 "scan.l"
{
++linenum;
ACTION_ECHO;
@@ -1766,12 +1768,12 @@ YY_RULE_SETUP
case 30:
YY_RULE_SETUP
-#line 184 "scan.l"
+#line 185 "scan.l"
/* separates name and definition */
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 186 "scan.l"
+#line 187 "scan.l"
{
strcpy( (char *) nmdef, yytext );
@@ -1789,7 +1791,7 @@ YY_RULE_SETUP
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 201 "scan.l"
+#line 202 "scan.l"
{
if ( ! didadef )
synerr( _( "incomplete name definition" ) );
@@ -1801,94 +1803,94 @@ YY_RULE_SETUP
case 33:
YY_RULE_SETUP
-#line 211 "scan.l"
+#line 212 "scan.l"
++linenum; BEGIN(INITIAL);
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 212 "scan.l"
+#line 213 "scan.l"
option_sense = true;
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 214 "scan.l"
+#line 215 "scan.l"
return '=';
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 216 "scan.l"
+#line 217 "scan.l"
option_sense = ! option_sense;
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 218 "scan.l"
+#line 219 "scan.l"
csize = option_sense ? 128 : 256;
YY_BREAK
case 38:
YY_RULE_SETUP
-#line 219 "scan.l"
+#line 220 "scan.l"
csize = option_sense ? 256 : 128;
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 221 "scan.l"
+#line 222 "scan.l"
long_align = option_sense;
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 222 "scan.l"
+#line 223 "scan.l"
{
action_define( "YY_ALWAYS_INTERACTIVE", option_sense );
}
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 225 "scan.l"
+#line 226 "scan.l"
yytext_is_array = option_sense;
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 226 "scan.l"
+#line 227 "scan.l"
backing_up_report = option_sense;
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 227 "scan.l"
+#line 228 "scan.l"
interactive = ! option_sense;
YY_BREAK
case 44:
YY_RULE_SETUP
-#line 228 "scan.l"
+#line 229 "scan.l"
C_plus_plus = option_sense;
YY_BREAK
case 45:
YY_RULE_SETUP
-#line 229 "scan.l"
+#line 230 "scan.l"
caseins = ! option_sense;
YY_BREAK
case 46:
YY_RULE_SETUP
-#line 230 "scan.l"
+#line 231 "scan.l"
caseins = option_sense;
YY_BREAK
case 47:
YY_RULE_SETUP
-#line 231 "scan.l"
+#line 232 "scan.l"
ddebug = option_sense;
YY_BREAK
case 48:
YY_RULE_SETUP
-#line 232 "scan.l"
+#line 233 "scan.l"
spprdflt = ! option_sense;
YY_BREAK
case 49:
YY_RULE_SETUP
-#line 233 "scan.l"
+#line 234 "scan.l"
useecs = option_sense;
YY_BREAK
case 50:
YY_RULE_SETUP
-#line 234 "scan.l"
+#line 235 "scan.l"
{
useecs = usemecs = false;
use_read = fullspd = true;
@@ -1896,7 +1898,7 @@ YY_RULE_SETUP
YY_BREAK
case 51:
YY_RULE_SETUP
-#line 238 "scan.l"
+#line 239 "scan.l"
{
useecs = usemecs = false;
use_read = fulltbl = true;
@@ -1904,22 +1906,22 @@ YY_RULE_SETUP
YY_BREAK
case 52:
YY_RULE_SETUP
-#line 242 "scan.l"
+#line 243 "scan.l"
ACTION_IFDEF("YY_NO_INPUT", ! option_sense);
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 243 "scan.l"
+#line 244 "scan.l"
interactive = option_sense;
YY_BREAK
case 54:
YY_RULE_SETUP
-#line 244 "scan.l"
+#line 245 "scan.l"
lex_compat = option_sense;
YY_BREAK
case 55:
YY_RULE_SETUP
-#line 245 "scan.l"
+#line 246 "scan.l"
{
action_define( "YY_MAIN", option_sense );
do_yywrap = ! option_sense;
@@ -1927,129 +1929,129 @@ YY_RULE_SETUP
YY_BREAK
case 56:
YY_RULE_SETUP
-#line 249 "scan.l"
+#line 250 "scan.l"
usemecs = option_sense;
YY_BREAK
case 57:
YY_RULE_SETUP
-#line 250 "scan.l"
+#line 251 "scan.l"
{
action_define( "YY_NEVER_INTERACTIVE", option_sense );
}
YY_BREAK
case 58:
YY_RULE_SETUP
-#line 253 "scan.l"
+#line 254 "scan.l"
performance_report += option_sense ? 1 : -1;
YY_BREAK
case 59:
YY_RULE_SETUP
-#line 254 "scan.l"
+#line 255 "scan.l"
yytext_is_array = ! option_sense;
YY_BREAK
case 60:
YY_RULE_SETUP
-#line 255 "scan.l"
+#line 256 "scan.l"
use_read = option_sense;
YY_BREAK
case 61:
YY_RULE_SETUP
-#line 256 "scan.l"
+#line 257 "scan.l"
reject_really_used = option_sense;
YY_BREAK
case 62:
YY_RULE_SETUP
-#line 257 "scan.l"
+#line 258 "scan.l"
action_define( "YY_STACK_USED", option_sense );
YY_BREAK
case 63:
YY_RULE_SETUP
-#line 258 "scan.l"
+#line 259 "scan.l"
do_stdinit = option_sense;
YY_BREAK
case 64:
YY_RULE_SETUP
-#line 259 "scan.l"
+#line 260 "scan.l"
use_stdout = option_sense;
YY_BREAK
case 65:
YY_RULE_SETUP
-#line 260 "scan.l"
+#line 261 "scan.l"
ACTION_IFDEF("YY_NO_UNPUT", ! option_sense);
YY_BREAK
case 66:
YY_RULE_SETUP
-#line 261 "scan.l"
+#line 262 "scan.l"
printstats = option_sense;
YY_BREAK
case 67:
YY_RULE_SETUP
-#line 262 "scan.l"
+#line 263 "scan.l"
nowarn = ! option_sense;
YY_BREAK
case 68:
YY_RULE_SETUP
-#line 263 "scan.l"
+#line 264 "scan.l"
do_yylineno = option_sense;
YY_BREAK
case 69:
YY_RULE_SETUP
-#line 264 "scan.l"
+#line 265 "scan.l"
yymore_really_used = option_sense;
YY_BREAK
case 70:
YY_RULE_SETUP
-#line 265 "scan.l"
+#line 266 "scan.l"
do_yywrap = option_sense;
YY_BREAK
case 71:
YY_RULE_SETUP
-#line 267 "scan.l"
+#line 268 "scan.l"
ACTION_IFDEF("YY_NO_PUSH_STATE", ! option_sense);
YY_BREAK
case 72:
YY_RULE_SETUP
-#line 268 "scan.l"
+#line 269 "scan.l"
ACTION_IFDEF("YY_NO_POP_STATE", ! option_sense);
YY_BREAK
case 73:
YY_RULE_SETUP
-#line 269 "scan.l"
+#line 270 "scan.l"
ACTION_IFDEF("YY_NO_TOP_STATE", ! option_sense);
YY_BREAK
case 74:
YY_RULE_SETUP
-#line 271 "scan.l"
+#line 272 "scan.l"
ACTION_IFDEF("YY_NO_SCAN_BUFFER", ! option_sense);
YY_BREAK
case 75:
YY_RULE_SETUP
-#line 272 "scan.l"
+#line 273 "scan.l"
ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense);
YY_BREAK
case 76:
YY_RULE_SETUP
-#line 273 "scan.l"
+#line 274 "scan.l"
ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense);
YY_BREAK
case 77:
YY_RULE_SETUP
-#line 275 "scan.l"
+#line 276 "scan.l"
return OPT_OUTFILE;
YY_BREAK
case 78:
YY_RULE_SETUP
-#line 276 "scan.l"
+#line 277 "scan.l"
return OPT_PREFIX;
YY_BREAK
case 79:
YY_RULE_SETUP
-#line 277 "scan.l"
+#line 278 "scan.l"
return OPT_YYCLASS;
YY_BREAK
case 80:
YY_RULE_SETUP
-#line 279 "scan.l"
+#line 280 "scan.l"
{
strcpy( nmstr, yytext + 1 );
nmstr[strlen( nmstr ) - 1] = '\0';
@@ -2058,7 +2060,7 @@ YY_RULE_SETUP
YY_BREAK
case 81:
YY_RULE_SETUP
-#line 285 "scan.l"
+#line 286 "scan.l"
{
format_synerr( _( "unrecognized %%option: %s" ),
yytext );
@@ -2068,28 +2070,28 @@ YY_RULE_SETUP
case 82:
YY_RULE_SETUP
-#line 292 "scan.l"
+#line 293 "scan.l"
++linenum; BEGIN(INITIAL);
YY_BREAK
case 83:
YY_RULE_SETUP
-#line 296 "scan.l"
+#line 297 "scan.l"
++bracelevel; yyless( 2 ); /* eat only %{ */
YY_BREAK
case 84:
YY_RULE_SETUP
-#line 297 "scan.l"
+#line 298 "scan.l"
--bracelevel; yyless( 2 ); /* eat only %} */
YY_BREAK
case 85:
YY_RULE_SETUP
-#line 299 "scan.l"
+#line 300 "scan.l"
ACTION_ECHO; /* indented code in prolog */
YY_BREAK
case 86:
YY_RULE_SETUP
-#line 301 "scan.l"
+#line 302 "scan.l"
{ /* non-indented code */
if ( bracelevel <= 0 )
{ /* not in %{ ... %} */
@@ -2104,16 +2106,16 @@ YY_RULE_SETUP
YY_BREAK
case 87:
YY_RULE_SETUP
-#line 313 "scan.l"
+#line 314 "scan.l"
ACTION_ECHO;
YY_BREAK
case 88:
YY_RULE_SETUP
-#line 314 "scan.l"
+#line 315 "scan.l"
++linenum; ACTION_ECHO;
YY_BREAK
case YY_STATE_EOF(SECT2PROLOG):
-#line 316 "scan.l"
+#line 317 "scan.l"
{
mark_prolog();
sectnum = 0;
@@ -2124,12 +2126,12 @@ case YY_STATE_EOF(SECT2PROLOG):
case 89:
YY_RULE_SETUP
-#line 324 "scan.l"
+#line 325 "scan.l"
++linenum; /* allow blank lines in section 2 */
YY_BREAK
case 90:
YY_RULE_SETUP
-#line 326 "scan.l"
+#line 327 "scan.l"
{
indented_code = false;
doing_codeblock = true;
@@ -2139,17 +2141,17 @@ YY_RULE_SETUP
YY_BREAK
case 91:
YY_RULE_SETUP
-#line 333 "scan.l"
+#line 334 "scan.l"
BEGIN(SC); return '<';
YY_BREAK
case 92:
YY_RULE_SETUP
-#line 334 "scan.l"
+#line 335 "scan.l"
return '^';
YY_BREAK
case 93:
YY_RULE_SETUP
-#line 335 "scan.l"
+#line 336 "scan.l"
BEGIN(QUOTE); return '"';
YY_BREAK
case 94:
@@ -2157,7 +2159,7 @@ case 94:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 336 "scan.l"
+#line 337 "scan.l"
BEGIN(NUM); return '{';
YY_BREAK
case 95:
@@ -2165,12 +2167,12 @@ case 95:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 337 "scan.l"
+#line 338 "scan.l"
return '$';
YY_BREAK
case 96:
YY_RULE_SETUP
-#line 339 "scan.l"
+#line 340 "scan.l"
{
bracelevel = 1;
BEGIN(PERCENT_BRACE_ACTION);
@@ -2185,12 +2187,12 @@ YY_RULE_SETUP
YY_BREAK
case 97:
YY_RULE_SETUP
-#line 350 "scan.l"
+#line 351 "scan.l"
continued_action = true; ++linenum; return '\n';
YY_BREAK
case 98:
YY_RULE_SETUP
-#line 352 "scan.l"
+#line 353 "scan.l"
{
yyless( yyleng - 2 ); /* put back '/', '*' */
bracelevel = 0;
@@ -2200,12 +2202,12 @@ YY_RULE_SETUP
YY_BREAK
case 99:
YY_RULE_SETUP
-#line 359 "scan.l"
+#line 360 "scan.l"
/* allow indented rules */
YY_BREAK
case 100:
YY_RULE_SETUP
-#line 361 "scan.l"
+#line 362 "scan.l"
{
/* This rule is separate from the one below because
* otherwise we get variable trailing context, so
@@ -2225,7 +2227,7 @@ YY_RULE_SETUP
YY_BREAK
case 101:
YY_RULE_SETUP
-#line 378 "scan.l"
+#line 379 "scan.l"
{
bracelevel = 0;
continued_action = false;
@@ -2241,15 +2243,15 @@ YY_RULE_SETUP
}
YY_BREAK
case 102:
-#line 393 "scan.l"
+#line 394 "scan.l"
case 103:
YY_RULE_SETUP
-#line 393 "scan.l"
+#line 394 "scan.l"
return EOF_OP;
YY_BREAK
case 104:
YY_RULE_SETUP
-#line 395 "scan.l"
+#line 396 "scan.l"
{
sectnum = 3;
BEGIN(SECT3);
@@ -2258,7 +2260,7 @@ YY_RULE_SETUP
YY_BREAK
case 105:
YY_RULE_SETUP
-#line 401 "scan.l"
+#line 402 "scan.l"
{
int cclval;
@@ -2295,7 +2297,7 @@ YY_RULE_SETUP
YY_BREAK
case 106:
YY_RULE_SETUP
-#line 435 "scan.l"
+#line 436 "scan.l"
{
Char *nmdefptr;
Char *ndlookup();
@@ -2332,24 +2334,24 @@ YY_RULE_SETUP
YY_BREAK
case 107:
YY_RULE_SETUP
-#line 469 "scan.l"
+#line 470 "scan.l"
return (unsigned char) yytext[0];
YY_BREAK
case 108:
YY_RULE_SETUP
-#line 470 "scan.l"
+#line 471 "scan.l"
RETURNCHAR;
YY_BREAK
case 109:
YY_RULE_SETUP
-#line 475 "scan.l"
+#line 476 "scan.l"
return (unsigned char) yytext[0];
YY_BREAK
case 110:
YY_RULE_SETUP
-#line 476 "scan.l"
+#line 477 "scan.l"
BEGIN(SECT2); return '>';
YY_BREAK
case 111:
@@ -2357,17 +2359,17 @@ case 111:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 477 "scan.l"
+#line 478 "scan.l"
BEGIN(CARETISBOL); return '>';
YY_BREAK
case 112:
YY_RULE_SETUP
-#line 478 "scan.l"
+#line 479 "scan.l"
RETURNNAME;
YY_BREAK
case 113:
YY_RULE_SETUP
-#line 479 "scan.l"
+#line 480 "scan.l"
{
format_synerr( _( "bad <start condition>: %s" ),
yytext );
@@ -2376,23 +2378,23 @@ YY_RULE_SETUP
case 114:
YY_RULE_SETUP
-#line 485 "scan.l"
+#line 486 "scan.l"
BEGIN(SECT2); return '^';
YY_BREAK
case 115:
YY_RULE_SETUP
-#line 489 "scan.l"
+#line 490 "scan.l"
RETURNCHAR;
YY_BREAK
case 116:
YY_RULE_SETUP
-#line 490 "scan.l"
+#line 491 "scan.l"
BEGIN(SECT2); return '"';
YY_BREAK
case 117:
YY_RULE_SETUP
-#line 492 "scan.l"
+#line 493 "scan.l"
{
synerr( _( "missing quote" ) );
BEGIN(SECT2);
@@ -2407,7 +2409,7 @@ case 118:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 502 "scan.l"
+#line 503 "scan.l"
BEGIN(CCL); return '^';
YY_BREAK
case 119:
@@ -2415,12 +2417,12 @@ case 119:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 503 "scan.l"
+#line 504 "scan.l"
return '^';
YY_BREAK
case 120:
YY_RULE_SETUP
-#line 504 "scan.l"
+#line 505 "scan.l"
BEGIN(CCL); RETURNCHAR;
YY_BREAK
@@ -2430,22 +2432,22 @@ case 121:
yy_c_buf_p = yy_cp = yy_bp + 1;
YY_DO_BEFORE_ACTION; /* set up yytext again */
YY_RULE_SETUP
-#line 508 "scan.l"
+#line 509 "scan.l"
return '-';
YY_BREAK
case 122:
YY_RULE_SETUP
-#line 509 "scan.l"
+#line 510 "scan.l"
RETURNCHAR;
YY_BREAK
case 123:
YY_RULE_SETUP
-#line 510 "scan.l"
+#line 511 "scan.l"
BEGIN(SECT2); return ']';
YY_BREAK
case 124:
YY_RULE_SETUP
-#line 511 "scan.l"
+#line 512 "scan.l"
{
synerr( _( "bad character class" ) );
BEGIN(SECT2);
@@ -2456,67 +2458,67 @@ YY_RULE_SETUP
case 125:
YY_RULE_SETUP
-#line 519 "scan.l"
+#line 520 "scan.l"
BEGIN(CCL); return CCE_ALNUM;
YY_BREAK
case 126:
YY_RULE_SETUP
-#line 520 "scan.l"
+#line 521 "scan.l"
BEGIN(CCL); return CCE_ALPHA;
YY_BREAK
case 127:
YY_RULE_SETUP
-#line 521 "scan.l"
+#line 522 "scan.l"
BEGIN(CCL); return CCE_BLANK;
YY_BREAK
case 128:
YY_RULE_SETUP
-#line 522 "scan.l"
+#line 523 "scan.l"
BEGIN(CCL); return CCE_CNTRL;
YY_BREAK
case 129:
YY_RULE_SETUP
-#line 523 "scan.l"
+#line 524 "scan.l"
BEGIN(CCL); return CCE_DIGIT;
YY_BREAK
case 130:
YY_RULE_SETUP
-#line 524 "scan.l"
+#line 525 "scan.l"
BEGIN(CCL); return CCE_GRAPH;
YY_BREAK
case 131:
YY_RULE_SETUP
-#line 525 "scan.l"
+#line 526 "scan.l"
BEGIN(CCL); return CCE_LOWER;
YY_BREAK
case 132:
YY_RULE_SETUP
-#line 526 "scan.l"
+#line 527 "scan.l"
BEGIN(CCL); return CCE_PRINT;
YY_BREAK
case 133:
YY_RULE_SETUP
-#line 527 "scan.l"
+#line 528 "scan.l"
BEGIN(CCL); return CCE_PUNCT;
YY_BREAK
case 134:
YY_RULE_SETUP
-#line 528 "scan.l"
+#line 529 "scan.l"
BEGIN(CCL); return CCE_SPACE;
YY_BREAK
case 135:
YY_RULE_SETUP
-#line 529 "scan.l"
+#line 530 "scan.l"
BEGIN(CCL); return CCE_UPPER;
YY_BREAK
case 136:
YY_RULE_SETUP
-#line 530 "scan.l"
+#line 531 "scan.l"
BEGIN(CCL); return CCE_XDIGIT;
YY_BREAK
case 137:
YY_RULE_SETUP
-#line 531 "scan.l"
+#line 532 "scan.l"
{
format_synerr(
_( "bad character class expression: %s" ),
@@ -2528,7 +2530,7 @@ YY_RULE_SETUP
case 138:
YY_RULE_SETUP
-#line 540 "scan.l"
+#line 541 "scan.l"
{
yylval = myctoi( yytext );
return NUMBER;
@@ -2536,17 +2538,17 @@ YY_RULE_SETUP
YY_BREAK
case 139:
YY_RULE_SETUP
-#line 545 "scan.l"
+#line 546 "scan.l"
return ',';
YY_BREAK
case 140:
YY_RULE_SETUP
-#line 546 "scan.l"
+#line 547 "scan.l"
BEGIN(SECT2); return '}';
YY_BREAK
case 141:
YY_RULE_SETUP
-#line 548 "scan.l"
+#line 549 "scan.l"
{
synerr( _( "bad character inside {}'s" ) );
BEGIN(SECT2);
@@ -2555,7 +2557,7 @@ YY_RULE_SETUP
YY_BREAK
case 142:
YY_RULE_SETUP
-#line 554 "scan.l"
+#line 555 "scan.l"
{
synerr( _( "missing }" ) );
BEGIN(SECT2);
@@ -2567,18 +2569,18 @@ YY_RULE_SETUP
case 143:
YY_RULE_SETUP
-#line 564 "scan.l"
+#line 565 "scan.l"
bracelevel = 0;
YY_BREAK
case 144:
YY_RULE_SETUP
-#line 566 "scan.l"
+#line 567 "scan.l"
ACTION_ECHO; yy_push_state( COMMENT );
YY_BREAK
case 145:
YY_RULE_SETUP
-#line 569 "scan.l"
+#line 570 "scan.l"
{
ACTION_ECHO;
CHECK_REJECT(yytext);
@@ -2586,7 +2588,7 @@ YY_RULE_SETUP
YY_BREAK
case 146:
YY_RULE_SETUP
-#line 573 "scan.l"
+#line 574 "scan.l"
{
ACTION_ECHO;
CHECK_YYMORE(yytext);
@@ -2595,12 +2597,12 @@ YY_RULE_SETUP
case 147:
YY_RULE_SETUP
-#line 579 "scan.l"
+#line 580 "scan.l"
ACTION_ECHO;
YY_BREAK
case 148:
YY_RULE_SETUP
-#line 580 "scan.l"
+#line 581 "scan.l"
{
++linenum;
ACTION_ECHO;
@@ -2620,37 +2622,37 @@ YY_RULE_SETUP
case 149:
YY_RULE_SETUP
-#line 598 "scan.l"
+#line 599 "scan.l"
ACTION_ECHO; ++bracelevel;
YY_BREAK
case 150:
YY_RULE_SETUP
-#line 599 "scan.l"
+#line 600 "scan.l"
ACTION_ECHO; --bracelevel;
YY_BREAK
case 151:
YY_RULE_SETUP
-#line 600 "scan.l"
+#line 601 "scan.l"
ACTION_ECHO;
YY_BREAK
case 152:
YY_RULE_SETUP
-#line 601 "scan.l"
+#line 602 "scan.l"
ACTION_ECHO;
YY_BREAK
case 153:
YY_RULE_SETUP
-#line 602 "scan.l"
+#line 603 "scan.l"
ACTION_ECHO; /* character constant */
YY_BREAK
case 154:
YY_RULE_SETUP
-#line 603 "scan.l"
+#line 604 "scan.l"
ACTION_ECHO; BEGIN(ACTION_STRING);
YY_BREAK
case 155:
YY_RULE_SETUP
-#line 604 "scan.l"
+#line 605 "scan.l"
{
++linenum;
ACTION_ECHO;
@@ -2666,41 +2668,41 @@ YY_RULE_SETUP
YY_BREAK
case 156:
YY_RULE_SETUP
-#line 616 "scan.l"
+#line 617 "scan.l"
ACTION_ECHO;
YY_BREAK
case 157:
YY_RULE_SETUP
-#line 620 "scan.l"
+#line 621 "scan.l"
ACTION_ECHO;
YY_BREAK
case 158:
YY_RULE_SETUP
-#line 621 "scan.l"
+#line 622 "scan.l"
ACTION_ECHO;
YY_BREAK
case 159:
YY_RULE_SETUP
-#line 622 "scan.l"
+#line 623 "scan.l"
++linenum; ACTION_ECHO;
YY_BREAK
case 160:
YY_RULE_SETUP
-#line 623 "scan.l"
+#line 624 "scan.l"
ACTION_ECHO; BEGIN(ACTION);
YY_BREAK
case 161:
YY_RULE_SETUP
-#line 624 "scan.l"
+#line 625 "scan.l"
ACTION_ECHO;
YY_BREAK
case YY_STATE_EOF(COMMENT):
case YY_STATE_EOF(ACTION):
case YY_STATE_EOF(ACTION_STRING):
-#line 627 "scan.l"
+#line 628 "scan.l"
{
synerr( _( "EOF encountered inside an action" ) );
yyterminate();
@@ -2708,7 +2710,7 @@ case YY_STATE_EOF(ACTION_STRING):
YY_BREAK
case 162:
YY_RULE_SETUP
-#line 633 "scan.l"
+#line 634 "scan.l"
{
yylval = myesc( (Char *) yytext );
@@ -2721,25 +2723,25 @@ YY_RULE_SETUP
case 163:
YY_RULE_SETUP
-#line 644 "scan.l"
+#line 645 "scan.l"
ECHO;
YY_BREAK
case YY_STATE_EOF(SECT3):
-#line 645 "scan.l"
+#line 646 "scan.l"
sectnum = 0; yyterminate();
YY_BREAK
case 164:
YY_RULE_SETUP
-#line 648 "scan.l"
+#line 649 "scan.l"
format_synerr( _( "bad character: %s" ), yytext );
YY_BREAK
case 165:
YY_RULE_SETUP
-#line 650 "scan.l"
+#line 651 "scan.l"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
-#line 2736 "scan.c"
+#line 2745 "scan.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(SECT2):
case YY_STATE_EOF(CODEBLOCK):
@@ -2894,7 +2896,11 @@ case YY_STATE_EOF(LINEDIR):
* EOB_ACT_END_OF_FILE - end of file
*/
+#ifdef YY_USE_PROTOS
static int yy_get_next_buffer(void)
+#else
+static int yy_get_next_buffer()
+#endif
{
char *dest = yy_current_buffer->yy_ch_buf;
char *source = yytext_ptr;
@@ -3026,7 +3032,11 @@ static int yy_get_next_buffer(void)
/* yy_get_previous_state - get the state just before the EOB char was reached */
+#ifdef YY_USE_PROTOS
static yy_state_type yy_get_previous_state(void)
+#else
+static yy_state_type yy_get_previous_state()
+#endif
{
yy_state_type yy_current_state;
char *yy_cp;
@@ -3135,10 +3145,15 @@ char *yy_bp;
#endif /* ifndef YY_NO_UNPUT */
+#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput()
#else
+#ifdef YY_USE_PROTOS
static int input(void)
+#else
+static int input()
+#endif
#endif
{
int c;
@@ -3176,7 +3191,7 @@ static int input(void)
/* Reset buffer status. */
yyrestart( yyin );
- /* FALLTHROUGH */
+ /* fall through */
case EOB_ACT_END_OF_FILE:
{
@@ -3207,6 +3222,7 @@ static int input(void)
return c;
}
+#endif /* ifndef YY_NO_INPUT */
#ifdef YY_USE_PROTOS
@@ -3510,7 +3526,11 @@ int new_state;
#ifndef YY_NO_POP_STATE
+#ifdef YY_USE_PROTOS
+static void yy_pop_state(void)
+#else
static void yy_pop_state()
+#endif
{
if ( --yy_start_stack_ptr < 0 )
YY_FATAL_ERROR( "start-condition stack underflow" );
@@ -3521,7 +3541,11 @@ static void yy_pop_state()
#ifndef YY_NO_TOP_STATE
+#ifdef YY_USE_PROTOS
+static int yy_top_state(void)
+#else
static int yy_top_state()
+#endif
{
return yy_start_stack[yy_start_stack_ptr - 1];
}
@@ -3640,7 +3664,7 @@ int main()
return 0;
}
#endif
-#line 650 "scan.l"
+#line 651 "scan.l"
diff --git a/usr.bin/objformat/Makefile b/usr.bin/objformat/Makefile
deleted file mode 100644
index 9550ff0..0000000
--- a/usr.bin/objformat/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-SCRIPTS=objformat.sh
-NO_MAN=
-
-.include <bsd.prog.mk>
-
diff --git a/usr.bin/objformat/objformat.sh b/usr.bin/objformat/objformat.sh
deleted file mode 100644
index edd9607..0000000
--- a/usr.bin/objformat/objformat.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#! /bin/sh
-# $FreeBSD$
-# /usr/bin/objformat has been obsolete and deprecated for years.
-# Please remove any build/configure script references. New software
-# should only have to only support elf on FreeBSD.
-#
-# FreeBSD-2.0, 2.1.x and 2.2.x will use a.out
-# FreeBSD-3.x will have a real /usr/bin/objformat and are more likely
-# to be elf than a.out.
-# Assume that FreeBSD-4.x will be using elf even though it is
-# **theoretically** possible to build an a.out world.
-# FreeBSD-5.x and higher only support elf.
-#
-
-echo '========================================================' 1>&2
-echo '== PLEASE REMOVE ALL REFERENCES TO /usr/bin/objformat ==' 1>&2
-echo '=========== IT HAS BEEN OBSOLETE FOR YEARS! ====-=======' 1>&2
-echo '========================================================' 1>&2
-(echo '========================================================' >/dev/tty) 2>/dev/null
-(echo '== PLEASE REMOVE ALL REFERENCES TO /usr/bin/objformat ==' >/dev/tty) 2>/dev/null
-(echo '=========== IT HAS BEEN OBSOLETE FOR YEARS! ====-=======' >/dev/tty) 2>/dev/null
-(echo '========================================================' >/dev/tty) 2>/dev/null
-# highlight the nag or it will never be fixed!
-sleep 10
-echo elf
-exit 0
diff --git a/usr.bin/seq/seq.c b/usr.bin/seq/seq.c
index f94ca00..c18c76c 100644
--- a/usr.bin/seq/seq.c
+++ b/usr.bin/seq/seq.c
@@ -251,7 +251,7 @@ valid_format(const char *fmt)
fmt++;
break;
}
- /* flags, width and precsision */
+ /* flags, width and precision */
if (isdigit((unsigned char)*fmt) ||
strchr("+- 0#.", *fmt))
continue;
@@ -329,7 +329,7 @@ unescape(char *orig)
*orig = c;
--cp;
continue;
- case 'x': /* hexidecimal number */
+ case 'x': /* hexadecimal number */
cp++; /* skip 'x' */
for (i = 0, c = 0;
isxdigit((unsigned char)*cp) && i < 2;
@@ -402,7 +402,7 @@ decimal_places(const char *number)
/*
* generate_format - create a format string
*
- * XXX to be bug for bug compatable with Plan9 and GNU return "%g"
+ * XXX to be bug for bug compatible with Plan9 and GNU return "%g"
* when "%g" prints as "%e" (this way no width adjustments are made)
*/
char *
diff --git a/usr.bin/yacc/Makefile b/usr.bin/yacc/Makefile
index c2f31a7..e8b1024 100644
--- a/usr.bin/yacc/Makefile
+++ b/usr.bin/yacc/Makefile
@@ -9,6 +9,4 @@ MAN= yacc.1 yyfix.1
LINKS= ${BINDIR}/yacc ${BINDIR}/byacc
MLINKS= yacc.1 byacc.1
-WARNS?= 2
-
.include <bsd.prog.mk>
diff --git a/usr.bin/yacc/closure.c b/usr.bin/yacc/closure.c
index 2124417..2aadb38 100644
--- a/usr.bin/yacc/closure.c
+++ b/usr.bin/yacc/closure.c
@@ -62,7 +62,7 @@ static unsigned *EFF;
static void
-set_EFF()
+set_EFF(void)
{
unsigned *row;
int symbol;
@@ -99,7 +99,7 @@ set_EFF()
void
-set_first_derives()
+set_first_derives(void)
{
unsigned *rrow;
unsigned *vrow;
@@ -149,14 +149,12 @@ set_first_derives()
print_first_derives();
#endif
- FREE(EFF);
+ free(EFF);
}
void
-closure(nucleus, n)
-short *nucleus;
-int n;
+closure(short *nucleus, int n)
{
int ruleno;
unsigned word;
@@ -224,19 +222,18 @@ int n;
void
-finalize_closure()
+finalize_closure(void)
{
- FREE(itemset);
- FREE(ruleset);
- FREE(first_derives + ntokens * WORDSIZE(nrules));
+ free(itemset);
+ free(ruleset);
+ free(first_derives + ntokens * WORDSIZE(nrules));
}
#ifdef DEBUG
static void
-print_closure(n)
-int n;
+print_closure(int n)
{
short *isp;
@@ -247,7 +244,7 @@ int n;
static void
-print_EFF()
+print_EFF(void)
{
int i, j;
unsigned *rowp;
@@ -279,7 +276,7 @@ print_EFF()
static void
-print_first_derives()
+print_first_derives(void)
{
int i;
int j;
diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h
index 772e912..2fdac73 100644
--- a/usr.bin/yacc/defs.h
+++ b/usr.bin/yacc/defs.h
@@ -133,12 +133,8 @@
/* storage allocation macros */
-#define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
-#define FREE(x) (free((char*)(x)))
-#define MALLOC(n) (malloc((unsigned)(n)))
#define NEW(t) ((t*)allocate(sizeof(t)))
-#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
-#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
+#define NEW2(n,t) ((t*)allocate((n)*sizeof(t)))
/* the structure of a symbol table entry */
@@ -304,7 +300,7 @@ extern short final_state;
/* global functions */
-char *allocate(unsigned);
+void *allocate(size_t);
void closure(short *, int);
void create_symbol_table(void);
void default_action_warning(void);
diff --git a/usr.bin/yacc/error.c b/usr.bin/yacc/error.c
index 9940dbc..ed269b6 100644
--- a/usr.bin/yacc/error.c
+++ b/usr.bin/yacc/error.c
@@ -49,8 +49,7 @@ __FBSDID("$FreeBSD$");
static void print_pos(char *, char *);
void
-fatal(msg)
-const char *msg;
+fatal(const char *msg)
{
warnx("f - %s", msg);
done(2);
@@ -58,7 +57,7 @@ const char *msg;
void
-no_space()
+no_space(void)
{
warnx("f - out of space");
done(2);
@@ -66,8 +65,7 @@ no_space()
void
-open_error(filename)
-const char *filename;
+open_error(const char *filename)
{
warnx("f - cannot open \"%s\"", filename);
done(2);
@@ -75,7 +73,7 @@ const char *filename;
void
-unexpected_EOF()
+unexpected_EOF(void)
{
warnx("e - line %d of \"%s\", unexpected end-of-file",
lineno, input_file_name);
@@ -84,9 +82,7 @@ unexpected_EOF()
static void
-print_pos(st_line, st_cptr)
-char *st_line;
-char *st_cptr;
+print_pos(char *st_line, char *st_cptr)
{
char *s;
@@ -112,10 +108,7 @@ char *st_cptr;
void
-syntax_error(st_lineno, st_line, st_cptr)
-int st_lineno;
-char *st_line;
-char *st_cptr;
+syntax_error(int st_lineno, char *st_line, char *st_cptr)
{
warnx("e - line %d of \"%s\", syntax error",
st_lineno, input_file_name);
@@ -125,10 +118,7 @@ char *st_cptr;
void
-unterminated_comment(c_lineno, c_line, c_cptr)
-int c_lineno;
-char *c_line;
-char *c_cptr;
+unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
{
warnx("e - line %d of \"%s\", unmatched /*",
c_lineno, input_file_name);
@@ -138,10 +128,7 @@ char *c_cptr;
void
-unterminated_string(s_lineno, s_line, s_cptr)
-int s_lineno;
-char *s_line;
-char *s_cptr;
+unterminated_string(int s_lineno, char *s_line, char *s_cptr)
{
warnx("e - line %d of \"%s\", unterminated string",
s_lineno, input_file_name);
@@ -151,10 +138,7 @@ char *s_cptr;
void
-unterminated_text(t_lineno, t_line, t_cptr)
-int t_lineno;
-char *t_line;
-char *t_cptr;
+unterminated_text(int t_lineno, char *t_line, char *t_cptr)
{
warnx("e - line %d of \"%s\", unmatched %%{",
t_lineno, input_file_name);
@@ -164,10 +148,7 @@ char *t_cptr;
void
-unterminated_union(u_lineno, u_line, u_cptr)
-int u_lineno;
-char *u_line;
-char *u_cptr;
+unterminated_union(int u_lineno, char *u_line, char *u_cptr)
{
warnx("e - line %d of \"%s\", unterminated %%union declaration",
u_lineno, input_file_name);
@@ -177,8 +158,7 @@ char *u_cptr;
void
-over_unionized(u_cptr)
-char *u_cptr;
+over_unionized(char *u_cptr)
{
warnx("e - line %d of \"%s\", too many %%union declarations",
lineno, input_file_name);
@@ -188,10 +168,7 @@ char *u_cptr;
void
-illegal_tag(t_lineno, t_line, t_cptr)
-int t_lineno;
-char *t_line;
-char *t_cptr;
+illegal_tag(int t_lineno, char *t_line, char *t_cptr)
{
warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
print_pos(t_line, t_cptr);
@@ -200,8 +177,7 @@ char *t_cptr;
void
-illegal_character(c_cptr)
-char *c_cptr;
+illegal_character(char *c_cptr)
{
warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
print_pos(line, c_cptr);
@@ -210,8 +186,7 @@ char *c_cptr;
void
-used_reserved(s)
-char *s;
+used_reserved(char *s)
{
warnx("e - line %d of \"%s\", illegal use of reserved symbol %s",
lineno, input_file_name, s);
@@ -220,8 +195,7 @@ char *s;
void
-tokenized_start(s)
-char *s;
+tokenized_start(char *s)
{
warnx("e - line %d of \"%s\", the start symbol %s cannot be \
declared to be a token", lineno, input_file_name, s);
@@ -230,8 +204,7 @@ declared to be a token", lineno, input_file_name, s);
void
-retyped_warning(s)
-char *s;
+retyped_warning(char *s)
{
warnx("w - line %d of \"%s\", the type of %s has been redeclared",
lineno, input_file_name, s);
@@ -239,8 +212,7 @@ char *s;
void
-reprec_warning(s)
-char *s;
+reprec_warning(char *s)
{
warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
lineno, input_file_name, s);
@@ -248,8 +220,7 @@ char *s;
void
-revalued_warning(s)
-char *s;
+revalued_warning(char *s)
{
warnx("w - line %d of \"%s\", the value of %s has been redeclared",
lineno, input_file_name, s);
@@ -257,8 +228,7 @@ char *s;
void
-terminal_start(s)
-char *s;
+terminal_start(char *s)
{
warnx("e - line %d of \"%s\", the start symbol %s is a token",
lineno, input_file_name, s);
@@ -267,7 +237,7 @@ char *s;
void
-restarted_warning()
+restarted_warning(void)
{
warnx("w - line %d of \"%s\", the start symbol has been redeclared",
lineno, input_file_name);
@@ -275,7 +245,7 @@ restarted_warning()
void
-no_grammar()
+no_grammar(void)
{
warnx("e - line %d of \"%s\", no grammar has been specified",
lineno, input_file_name);
@@ -284,8 +254,7 @@ no_grammar()
void
-terminal_lhs(s_lineno)
-int s_lineno;
+terminal_lhs(int s_lineno)
{
warnx("e - line %d of \"%s\", a token appears on the lhs of a production",
s_lineno, input_file_name);
@@ -294,7 +263,7 @@ int s_lineno;
void
-prec_redeclared()
+prec_redeclared(void)
{
warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
lineno, input_file_name);
@@ -302,10 +271,7 @@ prec_redeclared()
void
-unterminated_action(a_lineno, a_line, a_cptr)
-int a_lineno;
-char *a_line;
-char *a_cptr;
+unterminated_action(int a_lineno, char *a_line, char *a_cptr)
{
warnx("e - line %d of \"%s\", unterminated action",
a_lineno, input_file_name);
@@ -315,9 +281,7 @@ char *a_cptr;
void
-dollar_warning(a_lineno, i)
-int a_lineno;
-int i;
+dollar_warning(int a_lineno, int i)
{
warnx("w - line %d of \"%s\", $%d references beyond the \
end of the current rule", a_lineno, input_file_name, i);
@@ -325,10 +289,7 @@ end of the current rule", a_lineno, input_file_name, i);
void
-dollar_error(a_lineno, a_line, a_cptr)
-int a_lineno;
-char *a_line;
-char *a_cptr;
+dollar_error(int a_lineno, char *a_line, char *a_cptr)
{
warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
print_pos(a_line, a_cptr);
@@ -337,7 +298,7 @@ char *a_cptr;
void
-untyped_lhs()
+untyped_lhs(void)
{
warnx("e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
done(1);
@@ -345,9 +306,7 @@ untyped_lhs()
void
-untyped_rhs(i, s)
-int i;
-char *s;
+untyped_rhs(int i, char *s)
{
warnx("e - line %d of \"%s\", $%d (%s) is untyped",
lineno, input_file_name, i, s);
@@ -356,8 +315,7 @@ char *s;
void
-unknown_rhs(i)
-int i;
+unknown_rhs(int i)
{
warnx("e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
done(1);
@@ -365,7 +323,7 @@ int i;
void
-default_action_warning()
+default_action_warning(void)
{
warnx("w - line %d of \"%s\", the default action assigns an \
undefined value to $$", lineno, input_file_name);
@@ -373,8 +331,7 @@ undefined value to $$", lineno, input_file_name);
void
-undefined_goal(s)
-char *s;
+undefined_goal(char *s)
{
warnx("e - the start symbol %s is undefined", s);
done(1);
@@ -382,8 +339,7 @@ char *s;
void
-undefined_symbol_warning(s)
-char *s;
+undefined_symbol_warning(char *s)
{
warnx("w - the symbol %s is undefined", s);
}
diff --git a/usr.bin/yacc/lalr.c b/usr.bin/yacc/lalr.c
index 95d87de..1b62237 100644
--- a/usr.bin/yacc/lalr.c
+++ b/usr.bin/yacc/lalr.c
@@ -96,7 +96,7 @@ static int top;
void
-lalr()
+lalr(void)
{
tokensetsize = WORDSIZE(ntokens);
@@ -116,7 +116,7 @@ lalr()
static void
-set_state_table()
+set_state_table(void)
{
core *sp;
@@ -128,7 +128,7 @@ set_state_table()
static void
-set_accessing_symbol()
+set_accessing_symbol(void)
{
core *sp;
@@ -140,7 +140,7 @@ set_accessing_symbol()
static void
-set_shift_table()
+set_shift_table(void)
{
shifts *sp;
@@ -152,7 +152,7 @@ set_shift_table()
static void
-set_reduction_table()
+set_reduction_table(void)
{
reductions *rp;
@@ -164,7 +164,7 @@ set_reduction_table()
static void
-set_maxrhs()
+set_maxrhs(void)
{
short *itemp;
short *item_end;
@@ -193,7 +193,7 @@ set_maxrhs()
static void
-initialize_LA()
+initialize_LA(void)
{
int i, j, k;
reductions *rp;
@@ -231,7 +231,7 @@ initialize_LA()
static void
-set_goto_map()
+set_goto_map(void)
{
shifts *sp;
int i;
@@ -293,7 +293,7 @@ set_goto_map()
}
}
- FREE(temp_map + ntokens);
+ free(temp_map + ntokens);
}
@@ -301,9 +301,7 @@ set_goto_map()
/* Map_goto maps a state/symbol pair into its numeric representation. */
static int
-map_goto(state, symbol)
-int state;
-int symbol;
+map_goto(int state, int symbol)
{
int high;
int low;
@@ -330,7 +328,7 @@ int symbol;
static void
-initialize_F()
+initialize_F(void)
{
int i;
int j;
@@ -398,17 +396,17 @@ initialize_F()
for (i = 0; i < ngotos; i++)
{
if (reads[i])
- FREE(reads[i]);
+ free(reads[i]);
}
- FREE(reads);
- FREE(edge);
+ free(reads);
+ free(edge);
}
static void
-build_relations()
+build_relations(void)
{
int i;
int j;
@@ -489,20 +487,19 @@ build_relations()
for (i = 0; i < ngotos; i++)
if (includes[i])
- FREE(includes[i]);
+ free(includes[i]);
- FREE(includes);
+ free(includes);
includes = new_includes;
- FREE(edge);
- FREE(states);
+ free(edge);
+ free(states);
}
static void
-add_lookback_edge(stateno, ruleno, gotono)
-int stateno, ruleno, gotono;
+add_lookback_edge(int stateno, int ruleno, int gotono)
{
int i, k;
int found;
@@ -529,9 +526,7 @@ int stateno, ruleno, gotono;
static short **
-transpose(R, n)
-short **R;
-int n;
+transpose(short **R, int n)
{
short **new_R;
short **temp_R;
@@ -567,7 +562,7 @@ int n;
}
}
- FREE(nedges);
+ free(nedges);
for (i = 0; i < n; i++)
{
@@ -579,7 +574,7 @@ int n;
}
}
- FREE(temp_R);
+ free(temp_R);
return (new_R);
}
@@ -587,14 +582,14 @@ int n;
static void
-compute_FOLLOWS()
+compute_FOLLOWS(void)
{
digraph(includes);
}
static void
-compute_lookaheads()
+compute_lookaheads(void)
{
int i, n;
unsigned *fp1, *fp2, *fp3;
@@ -620,17 +615,16 @@ compute_lookaheads()
for (sp = lookback[i]; sp; sp = next)
{
next = sp->next;
- FREE(sp);
+ free(sp);
}
- FREE(lookback);
- FREE(F);
+ free(lookback);
+ free(F);
}
static void
-digraph(relation)
-short **relation;
+digraph(short **relation)
{
int i;
@@ -648,16 +642,14 @@ short **relation;
traverse(i, relation);
}
- FREE(INDEX);
- FREE(VERTICES);
+ free(INDEX);
+ free(VERTICES);
}
static void
-traverse(i, R)
-int i;
-short **R;
+traverse(int i, short **R)
{
unsigned *fp1;
unsigned *fp2;
diff --git a/usr.bin/yacc/lr0.c b/usr.bin/yacc/lr0.c
index cd8d1a1..a8035e6 100644
--- a/usr.bin/yacc/lr0.c
+++ b/usr.bin/yacc/lr0.c
@@ -91,7 +91,7 @@ static short *kernel_items;
static void
-allocate_itemsets()
+allocate_itemsets(void)
{
short *itemp;
short *item_end;
@@ -134,7 +134,7 @@ allocate_itemsets()
static void
-allocate_storage()
+allocate_storage(void)
{
allocate_itemsets();
shiftset = NEW2(nsyms, short);
@@ -144,7 +144,7 @@ allocate_storage()
static void
-append_states()
+append_states(void)
{
int i;
int j;
@@ -174,21 +174,21 @@ append_states()
static void
-free_storage()
+free_storage(void)
{
- FREE(shift_symbol);
- FREE(redset);
- FREE(shiftset);
- FREE(kernel_base);
- FREE(kernel_end);
- FREE(kernel_items);
- FREE(state_set);
+ free(shift_symbol);
+ free(redset);
+ free(shiftset);
+ free(kernel_base);
+ free(kernel_end);
+ free(kernel_items);
+ free(state_set);
}
static void
-generate_states()
+generate_states(void)
{
allocate_storage();
itemset = NEW2(nitems, short);
@@ -216,8 +216,7 @@ generate_states()
static int
-get_state(symbol)
-int symbol;
+get_state(int symbol)
{
int key;
short *isp1;
@@ -281,7 +280,7 @@ int symbol;
static void
-initialize_states()
+initialize_states(void)
{
int i;
short *start_derives;
@@ -291,7 +290,7 @@ initialize_states()
for (i = 0; start_derives[i] >= 0; ++i)
continue;
- p = (core *) MALLOC(sizeof(core) + i*sizeof(short));
+ p = malloc(sizeof(core) + i*sizeof(short));
if (p == 0) no_space();
p->next = 0;
@@ -309,7 +308,7 @@ initialize_states()
static void
-new_itemsets()
+new_itemsets(void)
{
int i;
int shiftcount;
@@ -346,8 +345,7 @@ new_itemsets()
static core *
-new_state(symbol)
-int symbol;
+new_state(int symbol)
{
int n;
core *p;
@@ -387,7 +385,7 @@ int symbol;
#if 0
/* show_cores is used for debugging */
-show_cores()
+show_cores(void)
{
core *p;
int i, j, k, n;
@@ -422,7 +420,7 @@ show_cores()
/* show_ritems is used for debugging */
-show_ritems()
+show_ritems(void)
{
int i;
@@ -432,7 +430,7 @@ show_ritems()
/* show_rrhs is used for debugging */
-show_rrhs()
+show_rrhs(void)
{
int i;
@@ -443,7 +441,7 @@ show_rrhs()
/* show_shifts is used for debugging */
-show_shifts()
+show_shifts(void)
{
shifts *p;
int i, j, k;
@@ -463,7 +461,7 @@ show_shifts()
static void
-save_shifts()
+save_shifts(void)
{
shifts *p;
short *sp1;
@@ -498,7 +496,7 @@ save_shifts()
static void
-save_reductions()
+save_reductions(void)
{
short *isp;
short *rp1;
@@ -548,7 +546,7 @@ save_reductions()
static void
-set_derives()
+set_derives(void)
{
int i, k;
int lhs;
@@ -581,14 +579,14 @@ set_derives()
#if 0
free_derives()
{
- FREE(derives[start_symbol]);
- FREE(derives);
+ free(derives[start_symbol]);
+ free(derives);
}
#endif
#ifdef DEBUG
static void
-print_derives()
+print_derives(void)
{
int i;
short *sp;
@@ -611,13 +609,13 @@ print_derives()
static void
-set_nullable()
+set_nullable(void)
{
int i, j;
int empty;
int done1;
- nullable = MALLOC(nsyms);
+ nullable = malloc(nsyms);
if (nullable == 0) no_space();
for (i = 0; i < nsyms; ++i)
@@ -661,15 +659,15 @@ set_nullable()
#if 0
-free_nullable()
+free_nullable(void)
{
- FREE(nullable);
+ free(nullable);
}
#endif
void
-lr0()
+lr0(void)
{
set_derives();
set_nullable();
diff --git a/usr.bin/yacc/main.c b/usr.bin/yacc/main.c
index 474de0b..1533ae7 100644
--- a/usr.bin/yacc/main.c
+++ b/usr.bin/yacc/main.c
@@ -115,8 +115,7 @@ static void usage(void);
volatile sig_atomic_t sigdie;
__dead2 void
-done(k)
-int k;
+done(int k)
{
if (action_file) { fclose(action_file); unlink(action_file_name); }
if (text_file) { fclose(text_file); unlink(text_file_name); }
@@ -127,8 +126,7 @@ int k;
static void
-onintr(signo)
- int signo __unused;
+onintr(int signo __unused)
{
sigdie = 1;
done(1);
@@ -136,7 +134,7 @@ onintr(signo)
static void
-set_signals()
+set_signals(void)
{
#ifdef SIGINT
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
@@ -154,7 +152,7 @@ set_signals()
static void
-usage()
+usage(void)
{
fprintf(stderr, "%s\n%s\n",
"usage: yacc [-dlrtv] [-b file_prefix] [-o output_filename]",
@@ -164,13 +162,11 @@ usage()
static void
-getargs(argc, argv)
-int argc;
-char *argv[];
+getargs(int argc, char *argv[])
{
int ch;
- while ((ch = getopt(argc, argv, "b:dlo:p:rtv")) != -1)
+ while ((ch = getopt(argc, argv, "b:dlo:p:rtvy")) != -1)
{
switch (ch)
{
@@ -206,6 +202,10 @@ char *argv[];
vflag = 1;
break;
+ case 'y':
+ /* for bison compatibility -- byacc is already POSIX compatible */
+ break;
+
default:
usage();
}
@@ -220,16 +220,15 @@ char *argv[];
}
-char *
-allocate(n)
-unsigned n;
+void *
+allocate(size_t n)
{
- char *p;
+ void *p;
p = NULL;
if (n)
{
- p = CALLOC(1, n);
+ p = calloc(1, n);
if (!p) no_space();
}
return (p);
@@ -237,7 +236,7 @@ unsigned n;
static void
-create_file_names()
+create_file_names(void)
{
int i, len;
const char *tmpdir;
@@ -250,11 +249,11 @@ create_file_names()
if (len && tmpdir[len-1] != '/')
++i;
- action_file_name = MALLOC(i);
+ action_file_name = malloc(i);
if (action_file_name == 0) no_space();
- text_file_name = MALLOC(i);
+ text_file_name = malloc(i);
if (text_file_name == 0) no_space();
- union_file_name = MALLOC(i);
+ union_file_name = malloc(i);
if (union_file_name == 0) no_space();
strcpy(action_file_name, tmpdir);
@@ -285,7 +284,7 @@ create_file_names()
else
{
len = strlen(file_prefix);
- output_file_name = MALLOC(len + 7);
+ output_file_name = malloc(len + 7);
if (output_file_name == 0)
no_space();
strcpy(output_file_name, file_prefix);
@@ -294,7 +293,7 @@ create_file_names()
if (rflag)
{
- code_file_name = MALLOC(len + 8);
+ code_file_name = malloc(len + 8);
if (code_file_name == 0)
no_space();
strcpy(code_file_name, file_prefix);
@@ -319,7 +318,7 @@ create_file_names()
if (dflag)
{
- defines_file_name = MALLOC(len + 7);
+ defines_file_name = malloc(len + 7);
if (defines_file_name == 0)
no_space();
strcpy(defines_file_name, file_prefix);
@@ -337,7 +336,7 @@ create_file_names()
if (vflag)
{
- verbose_file_name = MALLOC(len + 8);
+ verbose_file_name = malloc(len + 8);
if (verbose_file_name == 0)
no_space();
strcpy(verbose_file_name, file_prefix);
@@ -357,7 +356,7 @@ create_file_names()
static void
-open_files()
+open_files(void)
{
int fd;
diff --git a/usr.bin/yacc/mkpar.c b/usr.bin/yacc/mkpar.c
index 1dde4dd..8e897a2 100644
--- a/usr.bin/yacc/mkpar.c
+++ b/usr.bin/yacc/mkpar.c
@@ -73,7 +73,7 @@ static void unused_rules(void);
void
-make_parser()
+make_parser(void)
{
int i;
@@ -90,8 +90,7 @@ make_parser()
static action *
-parse_actions(stateno)
-int stateno;
+parse_actions(int stateno)
{
action *actions;
@@ -102,8 +101,7 @@ int stateno;
static action *
-get_shifts(stateno)
-int stateno;
+get_shifts(int stateno)
{
action *actions, *temp;
shifts *sp;
@@ -137,9 +135,7 @@ int stateno;
}
static action *
-add_reductions(stateno, actions)
-int stateno;
-action *actions;
+add_reductions(int stateno, action *actions)
{
int i, j, m, n;
int ruleno, tokensetsize;
@@ -163,9 +159,7 @@ action *actions;
static action *
-add_reduce(actions, ruleno, symbol)
-action *actions;
-int ruleno, symbol;
+add_reduce(action *actions, int ruleno, int symbol)
{
action *temp, *prev, *next;
@@ -204,7 +198,7 @@ int ruleno, symbol;
static void
-find_final_state()
+find_final_state(void)
{
int goal, i;
short *tostate;
@@ -222,12 +216,12 @@ find_final_state()
static void
-unused_rules()
+unused_rules(void)
{
int i;
action *p;
- rules_used = (short *) MALLOC(nrules*sizeof(short));
+ rules_used = malloc(nrules*sizeof(short));
if (rules_used == 0) no_space();
for (i = 0; i < nrules; ++i)
@@ -256,7 +250,7 @@ unused_rules()
static void
-remove_conflicts()
+remove_conflicts(void)
{
int i;
int symbol;
@@ -333,7 +327,7 @@ remove_conflicts()
static void
-total_conflicts()
+total_conflicts(void)
{
/* Warn if s/r != expect or if any r/r */
if ((SRtotal != SRexpect) || RRtotal)
@@ -352,8 +346,7 @@ total_conflicts()
static int
-sole_reduction(stateno)
-int stateno;
+sole_reduction(int stateno)
{
int count, ruleno;
action *p;
@@ -381,7 +374,7 @@ int stateno;
static void
-defreds()
+defreds(void)
{
int i;
@@ -391,26 +384,25 @@ defreds()
}
static void
-free_action_row(p)
-action *p;
+free_action_row(action *p)
{
action *q;
while (p)
{
q = p->next;
- FREE(p);
+ free(p);
p = q;
}
}
void
-free_parser()
+free_parser(void)
{
int i;
for (i = 0; i < nstates; i++)
free_action_row(parser[i]);
- FREE(parser);
+ free(parser);
}
diff --git a/usr.bin/yacc/output.c b/usr.bin/yacc/output.c
index b0b520a..0e1a9ed 100644
--- a/usr.bin/yacc/output.c
+++ b/usr.bin/yacc/output.c
@@ -95,7 +95,7 @@ static const char line_format[] = "#line %d \"%s\"\n";
void
-output()
+output(void)
{
free_itemsets();
free_shifts();
@@ -119,7 +119,7 @@ output()
static void
-output_prefix()
+output_prefix(void)
{
if (symbol_prefix == NULL)
symbol_prefix = "yy";
@@ -184,7 +184,7 @@ output_prefix()
static void
-output_rule_data()
+output_rule_data(void)
{
int i;
int j;
@@ -232,7 +232,7 @@ output_rule_data()
static void
-output_yydefred()
+output_yydefred(void)
{
int i, j;
@@ -260,7 +260,7 @@ output_yydefred()
static void
-output_actions()
+output_actions(void)
{
nvectors = 2*nstates + nvars;
@@ -270,15 +270,15 @@ output_actions()
width = NEW2(nvectors, short);
token_actions();
- FREE(lookaheads);
- FREE(LA);
- FREE(LAruleno);
- FREE(accessing_symbol);
+ free(lookaheads);
+ free(LA);
+ free(LAruleno);
+ free(accessing_symbol);
goto_actions();
- FREE(goto_map + ntokens);
- FREE(from_state);
- FREE(to_state);
+ free(goto_map + ntokens);
+ free(from_state);
+ free(to_state);
sort_actions();
pack_table();
@@ -289,7 +289,7 @@ output_actions()
static void
-token_actions()
+token_actions(void)
{
int i, j;
int shiftcount, reducecount;
@@ -370,11 +370,11 @@ token_actions()
}
}
}
- FREE(actionrow);
+ free(actionrow);
}
static void
-goto_actions()
+goto_actions(void)
{
int i, j, k;
@@ -403,12 +403,11 @@ goto_actions()
if (!rflag) outline += 2;
fprintf(output_file, "\n};\n");
- FREE(state_count);
+ free(state_count);
}
static int
-default_goto(symbol)
-int symbol;
+default_goto(int symbol)
{
int i;
int m;
@@ -444,9 +443,7 @@ int symbol;
static void
-save_column(symbol, default_state)
-int symbol;
-int default_state;
+save_column(int symbol, int default_state)
{
int i;
int m;
@@ -487,7 +484,7 @@ int default_state;
}
static void
-sort_actions()
+sort_actions(void)
{
int i;
int j;
@@ -523,7 +520,7 @@ sort_actions()
static void
-pack_table()
+pack_table(void)
{
int i;
int place;
@@ -558,14 +555,14 @@ pack_table()
for (i = 0; i < nvectors; i++)
{
if (froms[i])
- FREE(froms[i]);
+ free(froms[i]);
if (tos[i])
- FREE(tos[i]);
+ free(tos[i]);
}
- FREE(froms);
- FREE(tos);
- FREE(pos);
+ free(froms);
+ free(tos);
+ free(pos);
}
@@ -586,8 +583,7 @@ pack_table()
/* order. */
static int
-matching_vector(vector)
-int vector;
+matching_vector(int vector)
{
int i;
int j;
@@ -627,8 +623,7 @@ int vector;
static int
-pack_vector(vector)
-int vector;
+pack_vector(int vector)
{
int i, j, k;
int t;
@@ -705,7 +700,7 @@ int vector;
static void
-output_base()
+output_base(void)
{
int i, j;
@@ -767,13 +762,13 @@ output_base()
if (!rflag) outline += 2;
fprintf(output_file, "\n};\n");
- FREE(base);
+ free(base);
}
static void
-output_table()
+output_table(void)
{
int i;
int j;
@@ -800,13 +795,13 @@ output_table()
if (!rflag) outline += 2;
fprintf(output_file, "\n};\n");
- FREE(table);
+ free(table);
}
static void
-output_check()
+output_check(void)
{
int i;
int j;
@@ -831,13 +826,12 @@ output_check()
if (!rflag) outline += 2;
fprintf(output_file, "\n};\n");
- FREE(check);
+ free(check);
}
static int
-is_C_identifier(name)
-char *name;
+is_C_identifier(char *name)
{
char *s;
int c;
@@ -869,7 +863,7 @@ char *name;
static void
-output_defines()
+output_defines(void)
{
int c, i;
char *s;
@@ -928,7 +922,7 @@ output_defines()
static void
-output_stored_text()
+output_stored_text(void)
{
int c;
FILE *in, *out;
@@ -956,7 +950,7 @@ output_stored_text()
static void
-output_debug()
+output_debug(void)
{
int i, j, k, max;
char **symnam, *s;
@@ -978,7 +972,7 @@ output_debug()
++outline;
fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
- symnam = (char **) MALLOC((max+1)*sizeof(char *));
+ symnam = malloc((max+1)*sizeof(char *));
if (symnam == 0) no_space();
/* Note that it is not necessary to initialize the element */
@@ -1114,7 +1108,7 @@ output_debug()
}
if (!rflag) outline += 2;
fprintf(output_file, "\n};\n");
- FREE(symnam);
+ free(symnam);
if (!rflag) ++outline;
fprintf(output_file, "const char * const %srule[] = {\n", symbol_prefix);
@@ -1173,7 +1167,7 @@ output_debug()
static void
-output_stype()
+output_stype(void)
{
if (!unionized && ntags == 0)
{
@@ -1184,7 +1178,7 @@ output_stype()
static void
-output_trailing_text()
+output_trailing_text(void)
{
int c, last;
FILE *in, *out;
@@ -1242,7 +1236,7 @@ output_trailing_text()
static void
-output_semantic_actions()
+output_semantic_actions(void)
{
int c, last;
FILE *out;
@@ -1280,44 +1274,44 @@ output_semantic_actions()
static void
-free_itemsets()
+free_itemsets(void)
{
core *cp, *next;
- FREE(state_table);
+ free(state_table);
for (cp = first_state; cp; cp = next)
{
next = cp->next;
- FREE(cp);
+ free(cp);
}
}
static void
-free_shifts()
+free_shifts(void)
{
shifts *sp, *next;
- FREE(shift_table);
+ free(shift_table);
for (sp = first_shift; sp; sp = next)
{
next = sp->next;
- FREE(sp);
+ free(sp);
}
}
static void
-free_reductions()
+free_reductions(void)
{
reductions *rp, *next;
- FREE(reduction_table);
+ free(reduction_table);
for (rp = first_reduction; rp; rp = next)
{
next = rp->next;
- FREE(rp);
+ free(rp);
}
}
@@ -1338,9 +1332,9 @@ increase_maxtable(int loc)
newmax = maxtable;
do { newmax += 200; } while (newmax <= loc);
- table = (short *) REALLOC(table, newmax*sizeof(short));
+ table = realloc(table, newmax*sizeof(short));
if (table == 0) no_space();
- check = (short *) REALLOC(check, newmax*sizeof(short));
+ check = realloc(check, newmax*sizeof(short));
if (check == 0) no_space();
for (l = maxtable; l < newmax; ++l)
{
diff --git a/usr.bin/yacc/reader.c b/usr.bin/yacc/reader.c
index 7c1132d..f1ca8ae 100644
--- a/usr.bin/yacc/reader.c
+++ b/usr.bin/yacc/reader.c
@@ -120,14 +120,13 @@ static void skip_comment(void);
static void start_rule(bucket *, int);
static void
-cachec(c)
-int c;
+cachec(int c)
{
assert(cinc >= 0);
if (cinc >= cache_size)
{
cache_size += 256;
- cache = REALLOC(cache, cache_size);
+ cache = realloc(cache, cache_size);
if (cache == 0) no_space();
}
cache[cinc] = c;
@@ -136,7 +135,7 @@ int c;
static void
-get_line()
+get_line(void)
{
FILE *f = input_file;
int c;
@@ -144,7 +143,7 @@ get_line()
if (saw_eof || (c = getc(f)) == EOF)
{
- if (line) { FREE(line); line = 0; }
+ if (line) { free(line); line = 0; }
cptr = 0;
saw_eof = 1;
return;
@@ -152,9 +151,9 @@ get_line()
if (line == 0 || linesize != (LINESIZE + 1))
{
- if (line) FREE(line);
+ if (line) free(line);
linesize = LINESIZE + 1;
- line = MALLOC(linesize);
+ line = malloc(linesize);
if (line == 0) no_space();
}
@@ -167,7 +166,7 @@ get_line()
if (++i >= linesize)
{
linesize += LINESIZE;
- line = REALLOC(line, linesize);
+ line = realloc(line, linesize);
if (line == 0) no_space();
}
c = getc(f);
@@ -183,14 +182,14 @@ get_line()
static char *
-dup_line()
+dup_line(void)
{
char *p, *s, *t;
if (line == 0) return (0);
s = line;
while (*s != '\n') ++s;
- p = MALLOC(s - line + 1);
+ p = malloc(s - line + 1);
if (p == 0) no_space();
s = line;
@@ -201,7 +200,7 @@ dup_line()
static void
-skip_comment()
+skip_comment(void)
{
char *s;
@@ -215,7 +214,7 @@ skip_comment()
if (*s == '*' && s[1] == '/')
{
cptr = s + 2;
- FREE(st_line);
+ free(st_line);
return;
}
if (*s == '\n')
@@ -232,7 +231,7 @@ skip_comment()
static int
-nextc()
+nextc(void)
{
char *s;
@@ -294,7 +293,7 @@ nextc()
static int
-keyword()
+keyword(void)
{
int c;
char *t_cptr = cptr;
@@ -360,7 +359,7 @@ keyword()
static void
-copy_ident()
+copy_ident(void)
{
int c;
FILE *f = output_file;
@@ -390,7 +389,7 @@ copy_ident()
static void
-copy_text()
+copy_text(void)
{
int c;
int quote;
@@ -436,7 +435,7 @@ loop:
if (c == quote)
{
need_newline = 1;
- FREE(s_line);
+ free(s_line);
goto loop;
}
if (c == '\n')
@@ -488,7 +487,7 @@ loop:
{
putc('/', f);
++cptr;
- FREE(c_line);
+ free(c_line);
goto loop;
}
if (c == '\n')
@@ -508,7 +507,7 @@ loop:
{
if (need_newline) putc('\n', f);
++cptr;
- FREE(t_line);
+ free(t_line);
return;
}
/* FALLTHROUGH */
@@ -522,7 +521,7 @@ loop:
static void
-copy_union()
+copy_union(void)
{
int c;
int quote;
@@ -561,7 +560,7 @@ loop:
if (--depth == 0)
{
fprintf(text_file, " YYSTYPE;\n");
- FREE(u_line);
+ free(u_line);
return;
}
goto loop;
@@ -581,7 +580,7 @@ loop:
if (dflag) putc(c, union_file);
if (c == quote)
{
- FREE(s_line);
+ free(s_line);
goto loop;
}
if (c == '\n')
@@ -643,7 +642,7 @@ loop:
putc('/', text_file);
if (dflag) putc('/', union_file);
++cptr;
- FREE(c_line);
+ free(c_line);
goto loop;
}
if (c == '\n')
@@ -663,8 +662,7 @@ loop:
static int
-hexval(c)
-int c;
+hexval(int c)
{
if (c >= '0' && c <= '9')
return (c - '0');
@@ -677,7 +675,7 @@ int c;
static bucket *
-get_literal()
+get_literal(void)
{
int c, quote;
int i;
@@ -721,7 +719,7 @@ get_literal()
++cptr;
}
}
- if (n > UCHAR_MAX) illegal_character(c_cptr);
+ if (n > (int)UCHAR_MAX) illegal_character(c_cptr);
c = n;
break;
@@ -737,7 +735,7 @@ get_literal()
if (i < 0 || i >= 16) break;
++cptr;
n = (n << 4) + i;
- if (n > UCHAR_MAX) illegal_character(c_cptr);
+ if (n > (int)UCHAR_MAX) illegal_character(c_cptr);
}
c = n;
break;
@@ -753,10 +751,10 @@ get_literal()
}
cachec(c);
}
- FREE(s_line);
+ free(s_line);
n = cinc;
- s = MALLOC(n);
+ s = malloc(n);
if (s == 0) no_space();
for (i = 0; i < n; ++i)
@@ -809,15 +807,14 @@ get_literal()
bp->class = TERM;
if (n == 1 && bp->value == UNDEFINED)
bp->value = *(unsigned char *)s;
- FREE(s);
+ free(s);
return (bp);
}
static int
-is_reserved(name)
-char *name;
+is_reserved(char *name)
{
char *s;
@@ -838,7 +835,7 @@ char *name;
static bucket *
-get_name()
+get_name(void)
{
int c;
@@ -854,7 +851,7 @@ get_name()
static int
-get_number()
+get_number(void)
{
int c;
int n;
@@ -868,7 +865,7 @@ get_number()
static char *
-get_tag()
+get_tag(void)
{
int c;
int i;
@@ -903,24 +900,23 @@ get_tag()
{
tagmax += 16;
tag_table = (char **)
- (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *))
- : MALLOC(tagmax*sizeof(char *)));
+ (tag_table ? realloc(tag_table, tagmax*sizeof(char *))
+ : malloc(tagmax*sizeof(char *)));
if (tag_table == 0) no_space();
}
- s = MALLOC(cinc);
+ s = malloc(cinc);
if (s == 0) no_space();
strcpy(s, cache);
tag_table[ntags] = s;
++ntags;
- FREE(t_line);
+ free(t_line);
return (s);
}
static void
-declare_tokens(assoc)
-int assoc;
+declare_tokens(int assoc)
{
int c;
bucket *bp;
@@ -987,8 +983,7 @@ int assoc;
* grammar only a flag for yacc proper.
*/
static void
-declare_expect(assoc)
-int assoc;
+declare_expect(int assoc)
{
int c;
@@ -1027,7 +1022,7 @@ int assoc;
static void
-declare_types()
+declare_types(void)
{
int c;
bucket *bp;
@@ -1056,7 +1051,7 @@ declare_types()
static void
-declare_start()
+declare_start(void)
{
int c;
bucket *bp;
@@ -1075,12 +1070,12 @@ declare_start()
static void
-read_declarations()
+read_declarations(void)
{
int c, k;
cache_size = 256;
- cache = MALLOC(cache_size);
+ cache = malloc(cache_size);
if (cache == 0) no_space();
for (;;)
@@ -1129,11 +1124,11 @@ read_declarations()
static void
-initialize_grammar()
+initialize_grammar(void)
{
nitems = 4;
maxitems = 300;
- pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *));
+ pitem = malloc(maxitems*sizeof(bucket *));
if (pitem == 0) no_space();
pitem[0] = 0;
pitem[1] = 0;
@@ -1142,17 +1137,17 @@ initialize_grammar()
nrules = 3;
maxrules = 100;
- plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *));
+ plhs = malloc(maxrules*sizeof(bucket *));
if (plhs == 0) no_space();
plhs[0] = 0;
plhs[1] = 0;
plhs[2] = 0;
- rprec = (short *) MALLOC(maxrules*sizeof(short));
+ rprec = malloc(maxrules*sizeof(short));
if (rprec == 0) no_space();
rprec[0] = 0;
rprec[1] = 0;
rprec[2] = 0;
- rassoc = (char *) MALLOC(maxrules*sizeof(char));
+ rassoc = malloc(maxrules*sizeof(char));
if (rassoc == 0) no_space();
rassoc[0] = TOKEN;
rassoc[1] = TOKEN;
@@ -1161,29 +1156,29 @@ initialize_grammar()
static void
-expand_items()
+expand_items(void)
{
maxitems += 300;
- pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *));
+ pitem = realloc(pitem, maxitems*sizeof(bucket *));
if (pitem == 0) no_space();
}
static void
-expand_rules()
+expand_rules(void)
{
maxrules += 100;
- plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *));
+ plhs = realloc(plhs, maxrules*sizeof(bucket *));
if (plhs == 0) no_space();
- rprec = (short *) REALLOC(rprec, maxrules*sizeof(short));
+ rprec = realloc(rprec, maxrules*sizeof(short));
if (rprec == 0) no_space();
- rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char));
+ rassoc = realloc(rassoc, maxrules*sizeof(char));
if (rassoc == 0) no_space();
}
static void
-advance_to_start()
+advance_to_start(void)
{
int c;
bucket *bp;
@@ -1234,9 +1229,7 @@ advance_to_start()
static void
-start_rule(bp, s_lineno)
-bucket *bp;
-int s_lineno;
+start_rule(bucket *bp, int s_lineno)
{
if (bp->class == TERM)
terminal_lhs(s_lineno);
@@ -1250,7 +1243,7 @@ int s_lineno;
static void
-end_rule()
+end_rule(void)
{
int i;
@@ -1270,7 +1263,7 @@ end_rule()
static void
-insert_empty_rule()
+insert_empty_rule(void)
{
bucket *bp, **bpp;
@@ -1300,7 +1293,7 @@ insert_empty_rule()
static void
-add_symbol()
+add_symbol(void)
{
int c;
bucket *bp;
@@ -1332,7 +1325,7 @@ add_symbol()
static void
-copy_action()
+copy_action(void)
{
int c;
int i, n;
@@ -1374,7 +1367,7 @@ loop:
{
fprintf(f, "yyval.%s", tag);
++cptr;
- FREE(d_line);
+ free(d_line);
goto loop;
}
else if (isdigit(c))
@@ -1382,7 +1375,7 @@ loop:
i = get_number();
if (i > n) dollar_warning(d_lineno, i);
fprintf(f, "yyvsp[%d].%s", i - n, tag);
- FREE(d_line);
+ free(d_line);
goto loop;
}
else if (c == '-' && isdigit(cptr[1]))
@@ -1390,7 +1383,7 @@ loop:
++cptr;
i = -get_number() - n;
fprintf(f, "yyvsp[%d].%s", i, tag);
- FREE(d_line);
+ free(d_line);
goto loop;
}
else
@@ -1486,7 +1479,7 @@ loop:
putc(c, f);
if (c == quote)
{
- FREE(s_line);
+ free(s_line);
goto loop;
}
if (c == '\n')
@@ -1536,7 +1529,7 @@ loop:
{
putc('/', f);
++cptr;
- FREE(c_line);
+ free(c_line);
goto loop;
}
if (c == '\n')
@@ -1556,7 +1549,7 @@ loop:
static int
-mark_symbol()
+mark_symbol(void)
{
int c;
bucket *bp = NULL;
@@ -1600,7 +1593,7 @@ mark_symbol()
static void
-read_grammar()
+read_grammar(void)
{
int c;
@@ -1634,7 +1627,7 @@ read_grammar()
static void
-free_tags()
+free_tags(void)
{
int i;
@@ -1643,14 +1636,14 @@ free_tags()
for (i = 0; i < ntags; ++i)
{
assert(tag_table[i]);
- FREE(tag_table[i]);
+ free(tag_table[i]);
}
- FREE(tag_table);
+ free(tag_table);
}
static void
-pack_names()
+pack_names(void)
{
bucket *bp;
char *p, *s, *t;
@@ -1658,7 +1651,7 @@ pack_names()
name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */
for (bp = first_symbol; bp; bp = bp->next)
name_pool_size += strlen(bp->name) + 1;
- name_pool = MALLOC(name_pool_size);
+ name_pool = malloc(name_pool_size);
if (name_pool == 0) no_space();
strcpy(name_pool, "$accept");
@@ -1669,14 +1662,14 @@ pack_names()
p = t;
s = bp->name;
while ((*t++ = *s++)) continue;
- FREE(bp->name);
+ free(bp->name);
bp->name = p;
}
}
static void
-check_symbols()
+check_symbols(void)
{
bucket *bp;
@@ -1695,7 +1688,7 @@ check_symbols()
static void
-pack_symbols()
+pack_symbols(void)
{
bucket *bp;
bucket **v;
@@ -1711,16 +1704,16 @@ pack_symbols()
start_symbol = ntokens;
nvars = nsyms - ntokens;
- symbol_name = (char **) MALLOC(nsyms*sizeof(char *));
+ symbol_name = malloc(nsyms*sizeof(char *));
if (symbol_name == 0) no_space();
- symbol_value = (short *) MALLOC(nsyms*sizeof(short));
+ symbol_value = malloc(nsyms*sizeof(short));
if (symbol_value == 0) no_space();
- symbol_prec = (short *) MALLOC(nsyms*sizeof(short));
+ symbol_prec = malloc(nsyms*sizeof(short));
if (symbol_prec == 0) no_space();
- symbol_assoc = MALLOC(nsyms);
+ symbol_assoc = malloc(nsyms);
if (symbol_assoc == 0) no_space();
- v = (bucket **) MALLOC(nsyms*sizeof(bucket *));
+ v = malloc(nsyms*sizeof(bucket *));
if (v == 0) no_space();
v[0] = 0;
@@ -1815,25 +1808,25 @@ pack_symbols()
symbol_assoc[k] = v[i]->assoc;
}
- FREE(v);
+ free(v);
}
static void
-pack_grammar()
+pack_grammar(void)
{
int i, j;
int assoc, preced;
- ritem = (short *) MALLOC(nitems*sizeof(short));
+ ritem = malloc(nitems*sizeof(short));
if (ritem == 0) no_space();
- rlhs = (short *) MALLOC(nrules*sizeof(short));
+ rlhs = malloc(nrules*sizeof(short));
if (rlhs == 0) no_space();
- rrhs = (short *) MALLOC((nrules+1)*sizeof(short));
+ rrhs = malloc((nrules+1)*sizeof(short));
if (rrhs == 0) no_space();
- rprec = (short *) REALLOC(rprec, nrules*sizeof(short));
+ rprec = realloc(rprec, nrules*sizeof(short));
if (rprec == 0) no_space();
- rassoc = REALLOC(rassoc, nrules);
+ rassoc = realloc(rassoc, nrules);
if (rassoc == 0) no_space();
ritem[0] = -1;
@@ -1874,13 +1867,13 @@ pack_grammar()
}
rrhs[i] = j;
- FREE(plhs);
- FREE(pitem);
+ free(plhs);
+ free(pitem);
}
static void
-print_grammar()
+print_grammar(void)
{
int i, j, k;
int spacing;
@@ -1918,7 +1911,7 @@ print_grammar()
void
-reader()
+reader(void)
{
write_section(banner);
create_symbol_table();
diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c
index 434a7c2..4ea78c7 100644
--- a/usr.bin/yacc/skeleton.c
+++ b/usr.bin/yacc/skeleton.c
@@ -409,8 +409,7 @@ const char *trailer[] =
void
-write_section(section)
-const char *section[];
+write_section(const char *section[])
{
int c;
int i;
diff --git a/usr.bin/yacc/symtab.c b/usr.bin/yacc/symtab.c
index cb7b0bd..05a8d66 100644
--- a/usr.bin/yacc/symtab.c
+++ b/usr.bin/yacc/symtab.c
@@ -60,8 +60,7 @@ bucket *last_symbol;
static int
-hash(name)
-const char *name;
+hash(const char *name)
{
const char *s;
int c, k;
@@ -77,17 +76,16 @@ const char *name;
bucket *
-make_bucket(name)
-const char *name;
+make_bucket(const char *name)
{
bucket *bp;
assert(name);
- bp = (bucket *) MALLOC(sizeof(bucket));
+ bp = malloc(sizeof(bucket));
if (bp == 0) no_space();
bp->link = 0;
bp->next = 0;
- bp->name = MALLOC(strlen(name) + 1);
+ bp->name = malloc(strlen(name) + 1);
if (bp->name == 0) no_space();
bp->tag = 0;
bp->value = UNDEFINED;
@@ -104,8 +102,7 @@ const char *name;
bucket *
-lookup(name)
-char *name;
+lookup(char *name)
{
bucket *bp, **bpp;
@@ -128,12 +125,12 @@ char *name;
void
-create_symbol_table()
+create_symbol_table(void)
{
int i;
bucket *bp;
- symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *));
+ symbol_table = malloc(TABLE_SIZE*sizeof(bucket *));
if (symbol_table == 0) no_space();
for (i = 0; i < TABLE_SIZE; i++)
symbol_table[i] = 0;
@@ -149,21 +146,21 @@ create_symbol_table()
void
-free_symbol_table()
+free_symbol_table(void)
{
- FREE(symbol_table);
+ free(symbol_table);
symbol_table = 0;
}
void
-free_symbols()
+free_symbols(void)
{
bucket *p, *q;
for (p = first_symbol; p; p = q)
{
q = p->next;
- FREE(p);
+ free(p);
}
}
diff --git a/usr.bin/yacc/verbose.c b/usr.bin/yacc/verbose.c
index 282eaa3..3eeae40 100644
--- a/usr.bin/yacc/verbose.c
+++ b/usr.bin/yacc/verbose.c
@@ -60,18 +60,18 @@ static void print_shifts(action *);
static void print_state(int);
void
-verbose()
+verbose(void)
{
int i;
if (!vflag) return;
- null_rules = (short *) MALLOC(nrules*sizeof(short));
+ null_rules = malloc(nrules*sizeof(short));
if (null_rules == 0) no_space();
fprintf(verbose_file, "\f\n");
for (i = 0; i < nstates; i++)
print_state(i);
- FREE(null_rules);
+ free(null_rules);
if (nunused)
log_unused();
@@ -85,7 +85,7 @@ verbose()
static void
-log_unused()
+log_unused(void)
{
int i;
short *p;
@@ -105,7 +105,7 @@ log_unused()
static void
-log_conflicts()
+log_conflicts(void)
{
int i;
@@ -134,8 +134,7 @@ log_conflicts()
static void
-print_state(state)
-int state;
+print_state(int state)
{
if (state)
fprintf(verbose_file, "\n\n");
@@ -149,8 +148,7 @@ int state;
static void
-print_conflicts(state)
-int state;
+print_conflicts(int state)
{
int symbol, act = 0, number = 0;
action *p;
@@ -198,8 +196,7 @@ int state;
static void
-print_core(state)
-int state;
+print_core(int state)
{
int i;
int k;
@@ -235,8 +232,7 @@ int state;
static void
-print_nulls(state)
-int state;
+print_nulls(int state)
{
action *p;
int i, j, k, nnulls;
@@ -280,8 +276,7 @@ int state;
static void
-print_actions(stateno)
-int stateno;
+print_actions(int stateno)
{
action *p;
shifts *sp;
@@ -308,8 +303,7 @@ int stateno;
static void
-print_shifts(p)
-action *p;
+print_shifts(action *p)
{
int count;
action *q;
@@ -334,9 +328,7 @@ action *p;
static void
-print_reductions(p, defreduct)
-action *p;
-int defreduct;
+print_reductions(action *p, int defreduct)
{
int k, anyreds;
action *q;
@@ -373,8 +365,7 @@ int defreduct;
static void
-print_gotos(stateno)
-int stateno;
+print_gotos(int stateno)
{
int i, k;
int as;
diff --git a/usr.bin/yacc/warshall.c b/usr.bin/yacc/warshall.c
index 46d934d..e5a3ff0 100644
--- a/usr.bin/yacc/warshall.c
+++ b/usr.bin/yacc/warshall.c
@@ -48,9 +48,7 @@ __FBSDID("$FreeBSD$");
static void transitive_closure(unsigned *, int);
static void
-transitive_closure(R, n)
-unsigned *R;
-int n;
+transitive_closure(unsigned *R, int n)
{
int rowsize;
unsigned i;
@@ -101,9 +99,7 @@ int n;
}
void
-reflexive_transitive_closure(R, n)
-unsigned *R;
-int n;
+reflexive_transitive_closure(unsigned *R, int n)
{
int rowsize;
unsigned i;
diff --git a/usr.bin/yacc/yacc.1 b/usr.bin/yacc/yacc.1
index 56bacbb..b838872 100644
--- a/usr.bin/yacc/yacc.1
+++ b/usr.bin/yacc/yacc.1
@@ -44,7 +44,7 @@
.Nd an LALR(1) parser generator
.Sh SYNOPSIS
.Nm
-.Op Fl dlrtv
+.Op Fl dlrtvy
.Op Fl b Ar file_prefix
.Op Fl o Ar output_filename
.Op Fl p Ar symbol_prefix
@@ -118,6 +118,10 @@ so that debugging statements will be incorporated in the compiled code.
Cause a human-readable description of the generated parser to
be written to the file
.Pa y.output .
+.It Fl y
+NOOP for bison compatibility.
+.Nm
+is already designed to be POSIX yacc compatible.
.El
.Sh ENVIRONMENT
.Bl -tag -width ".Ev TMPDIR"
diff --git a/usr.sbin/apmd/apmd.8 b/usr.sbin/apmd/apmd.8
index 4ca8aae..3c2de63 100644
--- a/usr.sbin/apmd/apmd.8
+++ b/usr.sbin/apmd/apmd.8
@@ -1,6 +1,6 @@
.\" Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
.\" Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
-.\" Copyright (c) 1999 Yoshihiko SARUMARU Aq <mistral@imasy.or.jp>
+.\" Copyright (c) 1999 Yoshihiko SARUMARU <mistral@imasy.or.jp>
.\" Copyright (c) 1999 Norihiro Kumagai <kuma@nk.rim.or.jp>
.\" All rights reserved.
.\"
diff --git a/usr.sbin/config/configvers.h b/usr.sbin/config/configvers.h
index a2ce89a..322e648 100644
--- a/usr.sbin/config/configvers.h
+++ b/usr.sbin/config/configvers.h
@@ -26,7 +26,7 @@
* was a huge problem for 'make buildkernel' which was run with the installed
* /usr/sbin/config, not a cross built one. We started bumping the version
* number as a way to trap cases where the previous installworld was not
- * compatable with the new buildkernel. The buildtools phase and much more
+ * compatible with the new buildkernel. The buildtools phase and much more
* comprehensive error code returns solved this original problem.
*
* Most end-users will use buildkernel and the build tools from buildworld.
diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh
index 441d257..97e4c57 100644
--- a/usr.sbin/freebsd-update/freebsd-update.sh
+++ b/usr.sbin/freebsd-update/freebsd-update.sh
@@ -1470,7 +1470,7 @@ fetch_inspect_system () {
sort -k 3,3 -t '|' > $2.tmp
rm filelist
- # Check if an error occured during system inspection
+ # Check if an error occurred during system inspection
if [ -f .err ]; then
return 1
fi
diff --git a/usr.sbin/makefs/Makefile b/usr.sbin/makefs/Makefile
index 0356029..37eeb38 100644
--- a/usr.sbin/makefs/Makefile
+++ b/usr.sbin/makefs/Makefile
@@ -1,22 +1,23 @@
# $FreeBSD$
PROG= makefs
+
+CFLAGS+=-I${.CURDIR}
+
+SRCS= cd9660.c ffs.c \
+ getid.c \
+ makefs.c \
+ walk.c
MAN= makefs.8
WARNS?= 2
-CFLAGS+=-I${.CURDIR}
-SRCS= ffs.c getid.c makefs.c walk.c
+.include "${.CURDIR}/cd9660/Makefile.inc"
+.include "${.CURDIR}/ffs/Makefile.inc"
+.include "${.CURDIR}/compat/Makefile.inc"
-.PATH: ${.CURDIR}/ffs
-CFLAGS+=-I${.CURDIR}/ffs
CFLAGS+=-DHAVE_STRUCT_STAT_ST_FLAGS=1
CFLAGS+=-DHAVE_STRUCT_STAT_ST_GEN=1
-SRCS+= buf.c ffs_alloc.c ffs_balloc.c ffs_bswap.c ffs_subr.c mkfs.c ufs_bmap.c
-
-.PATH: ${.CURDIR}/compat
-CFLAGS+=-I${.CURDIR}/compat
-SRCS+= pwcache.c strsuftoll.c
.PATH: ${.CURDIR}/../mtree
CFLAGS+=-I${.CURDIR}/../mtree
diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c
new file mode 100644
index 0000000..bed764f
--- /dev/null
+++ b/usr.sbin/makefs/cd9660.c
@@ -0,0 +1,2154 @@
+/* $NetBSD: cd9660.c,v 1.27 2010/10/27 18:51:34 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (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) 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Luke Mewburn for Wasabi 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, 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 WASABI SYSTEMS, 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.
+ */
+/*
+ * 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.
+ * 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <string.h>
+#include <ctype.h>
+#include <sys/param.h>
+#include <sys/queue.h>
+
+#include "makefs.h"
+#include "cd9660.h"
+#include "cd9660/iso9660_rrip.h"
+#include "cd9660/cd9660_archimedes.h"
+
+/*
+ * Global variables
+ */
+iso9660_disk diskStructure;
+
+static void cd9660_finalize_PVD(void);
+static cd9660node *cd9660_allocate_cd9660node(void);
+static void cd9660_set_defaults(void);
+static int cd9660_arguments_set_string(const char *, const char *, int,
+ char, char *);
+static void cd9660_populate_iso_dir_record(
+ struct _iso_directory_record_cd9660 *, u_char, u_char, u_char,
+ const char *);
+static void cd9660_setup_root_node(void);
+static int cd9660_setup_volume_descriptors(void);
+#if 0
+static int cd9660_fill_extended_attribute_record(cd9660node *);
+#endif
+static void cd9660_sort_nodes(cd9660node *);
+static int cd9960_translate_node_common(cd9660node *);
+static int cd9660_translate_node(fsnode *, cd9660node *);
+static int cd9660_compare_filename(const char *, const char *);
+static void cd9660_sorted_child_insert(cd9660node *, cd9660node *);
+static int cd9660_handle_collisions(cd9660node *, int);
+static cd9660node *cd9660_rename_filename(cd9660node *, int, int);
+static void cd9660_copy_filenames(cd9660node *);
+static void cd9660_sorting_nodes(cd9660node *);
+static int cd9660_count_collisions(cd9660node *);
+static cd9660node *cd9660_rrip_move_directory(cd9660node *);
+static int cd9660_add_dot_records(cd9660node *);
+
+static void cd9660_convert_structure(fsnode *, cd9660node *, int,
+ int *, int *);
+static void cd9660_free_structure(cd9660node *);
+static int cd9660_generate_path_table(void);
+static int cd9660_level1_convert_filename(const char *, char *, int);
+static int cd9660_level2_convert_filename(const char *, char *, int);
+#if 0
+static int cd9660_joliet_convert_filename(const char *, char *, int);
+#endif
+static int cd9660_convert_filename(const char *, char *, int);
+static void cd9660_populate_dot_records(cd9660node *);
+static int64_t cd9660_compute_offsets(cd9660node *, int64_t);
+#if 0
+static int cd9660_copy_stat_info(cd9660node *, cd9660node *, int);
+#endif
+static cd9660node *cd9660_create_virtual_entry(const char *, cd9660node *, int,
+ int);
+static cd9660node *cd9660_create_file(const char *, cd9660node *, cd9660node *);
+static cd9660node *cd9660_create_directory(const char *, cd9660node *,
+ cd9660node *);
+static cd9660node *cd9660_create_special_directory(u_char, cd9660node *);
+
+
+/*
+ * Allocate and initalize a cd9660node
+ * @returns struct cd9660node * Pointer to new node, or NULL on error
+ */
+static cd9660node *
+cd9660_allocate_cd9660node(void)
+{
+ cd9660node *temp;
+
+ if ((temp = calloc(1, sizeof(cd9660node))) == NULL)
+ err(EXIT_FAILURE, "%s: calloc", __func__);
+ TAILQ_INIT(&temp->cn_children);
+ temp->parent = temp->dot_record = temp->dot_dot_record = NULL;
+ temp->ptnext = temp->ptprev = temp->ptlast = NULL;
+ temp->node = NULL;
+ temp->isoDirRecord = NULL;
+ temp->isoExtAttributes = NULL;
+ temp->rr_real_parent = temp->rr_relocated = NULL;
+ temp->su_tail_data = NULL;
+ return temp;
+}
+
+int cd9660_defaults_set = 0;
+
+/**
+* Set default values for cd9660 extension to makefs
+*/
+static void
+cd9660_set_defaults(void)
+{
+ /*Fix the sector size for now, though the spec allows for other sizes*/
+ diskStructure.sectorSize = 2048;
+
+ /* Set up defaults in our own structure */
+ diskStructure.verbose_level = 0;
+ diskStructure.keep_bad_images = 0;
+ diskStructure.follow_sym_links = 0;
+ diskStructure.isoLevel = 2;
+
+ diskStructure.rock_ridge_enabled = 0;
+ diskStructure.rock_ridge_renamed_dir_name = 0;
+ diskStructure.rock_ridge_move_count = 0;
+ diskStructure.rr_moved_dir = 0;
+
+ diskStructure.archimedes_enabled = 0;
+
+ diskStructure.include_padding_areas = 1;
+
+ /* Spec breaking functionality */
+ diskStructure.allow_deep_trees =
+ diskStructure.allow_start_dot =
+ diskStructure.allow_max_name =
+ diskStructure.allow_illegal_chars =
+ diskStructure.allow_lowercase =
+ diskStructure.allow_multidot =
+ diskStructure.omit_trailing_period = 0;
+
+ /* Make sure the PVD is clear */
+ memset(&diskStructure.primaryDescriptor, 0, 2048);
+
+ memset(diskStructure.primaryDescriptor.volume_set_id, 0x20,32);
+ memset(diskStructure.primaryDescriptor.publisher_id, 0x20,128);
+ memset(diskStructure.primaryDescriptor.preparer_id, 0x20,128);
+ memset(diskStructure.primaryDescriptor.application_id, 0x20,128);
+ memset(diskStructure.primaryDescriptor.copyright_file_id, 0x20,128);
+ memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,128);
+ memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,128);
+
+ strcpy(diskStructure.primaryDescriptor.system_id,"NetBSD");
+
+ cd9660_defaults_set = 1;
+
+ /* Boot support: Initially disabled */
+ diskStructure.has_generic_bootimage = 0;
+ diskStructure.generic_bootimage = NULL;
+
+ diskStructure.boot_image_directory = 0;
+ /*memset(diskStructure.boot_descriptor, 0, 2048);*/
+
+ diskStructure.is_bootable = 0;
+ TAILQ_INIT(&diskStructure.boot_images);
+ LIST_INIT(&diskStructure.boot_entries);
+}
+
+void
+cd9660_prep_opts(fsinfo_t *fsopts __unused)
+{
+ cd9660_set_defaults();
+}
+
+void
+cd9660_cleanup_opts(fsinfo_t *fsopts __unused)
+{
+
+}
+
+static int
+cd9660_arguments_set_string(const char *val, const char *fieldtitle, int length,
+ char testmode, char * dest)
+{
+ int len, test;
+
+ if (val == NULL)
+ warnx("error: The %s requires a string argument", fieldtitle);
+ else if ((len = strlen(val)) <= length) {
+ if (testmode == 'd')
+ test = cd9660_valid_d_chars(val);
+ else
+ test = cd9660_valid_a_chars(val);
+ if (test) {
+ memcpy(dest, val, len);
+ if (test == 2)
+ cd9660_uppercase_characters(dest, len);
+ return 1;
+ } else
+ warnx("error: The %s must be composed of "
+ "%c-characters", fieldtitle, testmode);
+ } else
+ warnx("error: The %s must be at most 32 characters long",
+ fieldtitle);
+ return 0;
+}
+
+/*
+ * Command-line parsing function
+ */
+
+int
+cd9660_parse_opts(const char *option, fsinfo_t *fsopts)
+{
+ char *var, *val;
+ int rv;
+ /* Set up allowed options - integer options ONLY */
+ option_t cd9660_options[] = {
+ { "l", &diskStructure.isoLevel, 1, 3, "ISO Level" },
+ { "isolevel", &diskStructure.isoLevel, 1, 3, "ISO Level" },
+ { "verbose", &diskStructure.verbose_level, 0, 2,
+ "Turns on verbose output" },
+ { "v", &diskStructure.verbose_level, 0 , 2,
+ "Turns on verbose output"},
+ { .name = NULL }
+ };
+
+ if (cd9660_defaults_set == 0)
+ cd9660_set_defaults();
+
+ /*
+ * Todo : finish implementing this, and make a function that
+ * parses them
+ */
+ /*
+ string_option_t cd9660_string_options[] = {
+ { "L", "Label", &diskStructure.primaryDescriptor.volume_id, 1, 32, "Disk Label", ISO_STRING_FILTER_DCHARS },
+ { NULL }
+ }
+ */
+
+ assert(option != NULL);
+
+ if (debug & DEBUG_FS_PARSE_OPTS)
+ printf("cd9660_parse_opts: got `%s'\n", option);
+
+ if ((var = strdup(option)) == NULL)
+ err(1, "allocating memory for copy of option string");
+ rv = 1;
+
+ val = strchr(var, '=');
+ if (val != NULL)
+ *val++ = '\0';
+
+ /* First handle options with no parameters */
+ if (strcmp(var, "h") == 0) {
+ diskStructure.displayHelp = 1;
+ rv = 1;
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "S", "follow-symlinks")) {
+ /* this is not handled yet */
+ diskStructure.follow_sym_links = 1;
+ rv = 1;
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "L", "label")) {
+ rv = cd9660_arguments_set_string(val, "Disk Label", 32, 'd',
+ diskStructure.primaryDescriptor.volume_id);
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "applicationid")) {
+ rv = cd9660_arguments_set_string(val, "Application Identifier", 128, 'a',
+ diskStructure.primaryDescriptor.application_id);
+ } else if(CD9660_IS_COMMAND_ARG_DUAL(var, "P", "publisher")) {
+ rv = cd9660_arguments_set_string(val, "Publisher Identifier",
+ 128, 'a', diskStructure.primaryDescriptor.publisher_id);
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "p", "preparer")) {
+ rv = cd9660_arguments_set_string(val, "Preparer Identifier",
+ 128, 'a', diskStructure.primaryDescriptor.preparer_id);
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "V", "volumeid")) {
+ rv = cd9660_arguments_set_string(val, "Volume Set Identifier",
+ 128, 'a', diskStructure.primaryDescriptor.volume_set_id);
+ /* Boot options */
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "B", "bootimage")) {
+ if (val == NULL)
+ warnx("error: The Boot Image parameter requires a valid boot information string");
+ else
+ rv = cd9660_add_boot_disk(val);
+ } else if (CD9660_IS_COMMAND_ARG(var, "bootimagedir")) {
+ /*
+ * XXXfvdl this is unused.
+ */
+ if (val == NULL)
+ errx(1, "error: The Boot Image Directory parameter"
+ " requires a directory name\n");
+ else {
+ if ((diskStructure.boot_image_directory =
+ malloc(strlen(val) + 1)) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_parse_opts");
+ exit(1);
+ }
+
+ /* BIG TODO: Add the max length function here */
+ cd9660_arguments_set_string(val, "Boot Image Directory",
+ 12 , 'd', diskStructure.boot_image_directory);
+ }
+ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "G", "generic-bootimage")) {
+ if (val == NULL)
+ warnx("error: The Boot Image parameter requires a valid boot information string");
+ else
+ rv = cd9660_add_generic_bootimage(val);
+ } else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding"))
+ diskStructure.include_padding_areas = 0;
+ /* RRIP */
+ else if (CD9660_IS_COMMAND_ARG_DUAL(var, "R", "rockridge"))
+ diskStructure.rock_ridge_enabled = 1;
+ else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes"))
+ diskStructure.archimedes_enabled = 1;
+ else if (CD9660_IS_COMMAND_ARG_DUAL(var, "K", "keep-bad-images"))
+ diskStructure.keep_bad_images = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "allow-deep-trees"))
+ diskStructure.allow_deep_trees = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "allow-max-name"))
+ diskStructure.allow_max_name = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "allow-illegal-chars"))
+ diskStructure.allow_illegal_chars = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "allow-lowercase"))
+ diskStructure.allow_lowercase = 1;
+ else if (CD9660_IS_COMMAND_ARG(var,"allow-multidot"))
+ diskStructure.allow_multidot = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "omit-trailing-period"))
+ diskStructure.omit_trailing_period = 1;
+ else if (CD9660_IS_COMMAND_ARG(var, "no-emul-boot") ||
+ CD9660_IS_COMMAND_ARG(var, "no-boot") ||
+ CD9660_IS_COMMAND_ARG(var, "hard-disk-boot")) {
+ cd9660_eltorito_add_boot_option(var, 0);
+
+ /* End of flag variables */
+ } else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) {
+ if (val == NULL) {
+ warnx("Option `%s' doesn't contain a value", var);
+ rv = 0;
+ } else {
+ cd9660_eltorito_add_boot_option(var, val);
+ }
+ } else {
+ if (val == NULL) {
+ warnx("Option `%s' doesn't contain a value", var);
+ rv = 0;
+ } else
+ rv = set_option(cd9660_options, var, val);
+ }
+
+ if (var)
+ free(var);
+ return (rv);
+}
+
+/*
+ * Main function for cd9660_makefs
+ * Builds the ISO image file
+ * @param const char *image The image filename to create
+ * @param const char *dir The directory that is being read
+ * @param struct fsnode *root The root node of the filesystem tree
+ * @param struct fsinfo_t *fsopts Any options
+ */
+void
+cd9660_makefs(const char *image, const char *dir, fsnode *root,
+ fsinfo_t *fsopts)
+{
+ int64_t startoffset;
+ int numDirectories;
+ uint64_t pathTableSectors;
+ int64_t firstAvailableSector;
+ int64_t totalSpace;
+ int error;
+ cd9660node *real_root;
+
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: ISO level is %i\n",
+ diskStructure.isoLevel);
+ if (diskStructure.isoLevel < 2 &&
+ diskStructure.allow_multidot)
+ errx(1, "allow-multidot requires iso level of 2\n");
+
+ assert(image != NULL);
+ assert(dir != NULL);
+ assert(root != NULL);
+
+ if (diskStructure.displayHelp) {
+ /*
+ * Display help here - probably want to put it in
+ * a separate function
+ */
+ return;
+ }
+
+ diskStructure.rootFilesystemPath = dir;
+
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: image %s directory %s root %p\n",
+ image, dir, root);
+
+ /* Set up some constants. Later, these will be defined with options */
+
+ /* Counter needed for path tables */
+ numDirectories = 0;
+
+ /* Convert tree to our own format */
+ /* Actually, we now need to add the REAL root node, at level 0 */
+
+ real_root = cd9660_allocate_cd9660node();
+ if ((real_root->isoDirRecord =
+ malloc( sizeof(iso_directory_record_cd9660) )) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_makefs");
+ exit(1);
+ }
+
+ /* Leave filename blank for root */
+ memset(real_root->isoDirRecord->name, 0,
+ ISO_FILENAME_MAXLENGTH_WITH_PADDING);
+
+ real_root->level = 0;
+ diskStructure.rootNode = real_root;
+ real_root->type = CD9660_TYPE_DIR;
+ error = 0;
+ real_root->node = root;
+ cd9660_convert_structure(root, real_root, 1, &numDirectories, &error);
+
+ if (TAILQ_EMPTY(&real_root->cn_children)) {
+ errx(1, "cd9660_makefs: converted directory is empty. "
+ "Tree conversion failed\n");
+ } else if (error != 0) {
+ errx(1, "cd9660_makefs: tree conversion failed\n");
+ } else {
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: tree converted\n");
+ }
+
+ /* Add the dot and dot dot records */
+ cd9660_add_dot_records(real_root);
+
+ cd9660_setup_root_node();
+
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: done converting tree\n");
+
+ /* non-SUSP extensions */
+ if (diskStructure.archimedes_enabled)
+ archimedes_convert_tree(diskStructure.rootNode);
+
+ /* Rock ridge / SUSP init pass */
+ if (diskStructure.rock_ridge_enabled) {
+ cd9660_susp_initialize(diskStructure.rootNode,
+ diskStructure.rootNode, NULL);
+ }
+
+ /* Build path table structure */
+ diskStructure.pathTableLength = cd9660_generate_path_table();
+
+ pathTableSectors = CD9660_BLOCKS(diskStructure.sectorSize,
+ diskStructure.pathTableLength);
+
+ firstAvailableSector = cd9660_setup_volume_descriptors();
+ if (diskStructure.is_bootable) {
+ firstAvailableSector = cd9660_setup_boot(firstAvailableSector);
+ if (firstAvailableSector < 0)
+ errx(1, "setup_boot failed");
+ }
+ /* LE first, then BE */
+ diskStructure.primaryLittleEndianTableSector = firstAvailableSector;
+ diskStructure.primaryBigEndianTableSector =
+ diskStructure.primaryLittleEndianTableSector + pathTableSectors;
+
+ /* Set the secondary ones to -1, not going to use them for now */
+ diskStructure.secondaryBigEndianTableSector = -1;
+ diskStructure.secondaryLittleEndianTableSector = -1;
+
+ diskStructure.dataFirstSector =
+ diskStructure.primaryBigEndianTableSector + pathTableSectors;
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: Path table conversion complete. "
+ "Each table is %i bytes, or %" PRIu64 " sectors.\n",
+ diskStructure.pathTableLength, pathTableSectors);
+
+ startoffset = diskStructure.sectorSize*diskStructure.dataFirstSector;
+
+ totalSpace = cd9660_compute_offsets(real_root, startoffset);
+
+ diskStructure.totalSectors = diskStructure.dataFirstSector +
+ CD9660_BLOCKS(diskStructure.sectorSize, totalSpace);
+
+ /* Disabled until pass 1 is done */
+ if (diskStructure.rock_ridge_enabled) {
+ diskStructure.susp_continuation_area_start_sector =
+ diskStructure.totalSectors;
+ diskStructure.totalSectors +=
+ CD9660_BLOCKS(diskStructure.sectorSize,
+ diskStructure.susp_continuation_area_size);
+ cd9660_susp_finalize(diskStructure.rootNode);
+ }
+
+
+ cd9660_finalize_PVD();
+
+ /* Add padding sectors, just for testing purposes right now */
+ /* diskStructure.totalSectors+=150; */
+
+ /* Debugging output */
+ if (diskStructure.verbose_level > 0) {
+ printf("cd9660_makefs: Sectors 0-15 reserved\n");
+ printf("cd9660_makefs: Primary path tables starts in sector %"
+ PRId64 "\n", diskStructure.primaryLittleEndianTableSector);
+ printf("cd9660_makefs: File data starts in sector %"
+ PRId64 "\n", diskStructure.dataFirstSector);
+ printf("cd9660_makefs: Total sectors: %"
+ PRId64 "\n", diskStructure.totalSectors);
+ }
+
+ /*
+ * Add padding sectors at the end
+ * TODO: Clean this up and separate padding
+ */
+ if (diskStructure.include_padding_areas)
+ diskStructure.totalSectors += 150;
+
+ cd9660_write_image(image);
+
+ if (diskStructure.verbose_level > 1) {
+ debug_print_volume_descriptor_information();
+ debug_print_tree(real_root,0);
+ debug_print_path_tree(real_root);
+ }
+
+ /* Clean up data structures */
+ cd9660_free_structure(real_root);
+
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_makefs: done\n");
+}
+
+/* Generic function pointer - implement later */
+typedef int (*cd9660node_func)(cd9660node *);
+
+static void
+cd9660_finalize_PVD(void)
+{
+ time_t tim;
+ unsigned char *temp;
+
+ /* Copy the root directory record */
+ temp = (unsigned char *) &diskStructure.primaryDescriptor;
+
+ /* root should be a fixed size of 34 bytes since it has no name */
+ memcpy(diskStructure.primaryDescriptor.root_directory_record,
+ diskStructure.rootNode->dot_record->isoDirRecord, 34);
+
+ /* In RRIP, this might be longer than 34 */
+ diskStructure.primaryDescriptor.root_directory_record[0] = 34;
+
+ /* Set up all the important numbers in the PVD */
+ cd9660_bothendian_dword(diskStructure.totalSectors,
+ (unsigned char *)diskStructure.primaryDescriptor.volume_space_size);
+ cd9660_bothendian_word(1,
+ (unsigned char *)diskStructure.primaryDescriptor.volume_set_size);
+ cd9660_bothendian_word(1,
+ (unsigned char *)
+ diskStructure.primaryDescriptor.volume_sequence_number);
+ cd9660_bothendian_word(diskStructure.sectorSize,
+ (unsigned char *)
+ diskStructure.primaryDescriptor.logical_block_size);
+ cd9660_bothendian_dword(diskStructure.pathTableLength,
+ (unsigned char *)diskStructure.primaryDescriptor.path_table_size);
+
+ cd9660_731(diskStructure.primaryLittleEndianTableSector,
+ (u_char *)diskStructure.primaryDescriptor.type_l_path_table);
+ cd9660_732(diskStructure.primaryBigEndianTableSector,
+ (u_char *)diskStructure.primaryDescriptor.type_m_path_table);
+
+ diskStructure.primaryDescriptor.file_structure_version[0] = 1;
+
+ /* Pad all strings with spaces instead of nulls */
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.volume_id, 32);
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.system_id, 32);
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.volume_set_id,
+ 128);
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.publisher_id,
+ 128);
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.preparer_id,
+ 128);
+ cd9660_pad_string_spaces(diskStructure.primaryDescriptor.application_id,
+ 128);
+ cd9660_pad_string_spaces(
+ diskStructure.primaryDescriptor.copyright_file_id, 128);
+ cd9660_pad_string_spaces(
+ diskStructure.primaryDescriptor.abstract_file_id, 128);
+ cd9660_pad_string_spaces(
+ diskStructure.primaryDescriptor.bibliographic_file_id, 128);
+
+ /* Setup dates */
+ time(&tim);
+ cd9660_time_8426(
+ (unsigned char *)diskStructure.primaryDescriptor.creation_date,
+ tim);
+ cd9660_time_8426(
+ (unsigned char *)diskStructure.primaryDescriptor.modification_date,
+ tim);
+
+ /*
+ cd9660_set_date(diskStructure.primaryDescriptor.expiration_date, now);
+ */
+
+ memset(diskStructure.primaryDescriptor.expiration_date, '0' ,17);
+ cd9660_time_8426(
+ (unsigned char *)diskStructure.primaryDescriptor.effective_date,
+ tim);
+}
+
+static void
+cd9660_populate_iso_dir_record(struct _iso_directory_record_cd9660 *record,
+ u_char ext_attr_length, u_char flags,
+ u_char name_len, const char * name)
+{
+ record->ext_attr_length[0] = ext_attr_length;
+ record->flags[0] = ISO_FLAG_CLEAR | flags;
+ record->file_unit_size[0] = 0;
+ record->interleave[0] = 0;
+ cd9660_bothendian_word(1, record->volume_sequence_number);
+ record->name_len[0] = name_len;
+ memset(record->name, '\0', sizeof (record->name));
+ memcpy(record->name, name, name_len);
+ record->length[0] = 33 + name_len;
+
+ /* Todo : better rounding */
+ record->length[0] += (record->length[0] & 1) ? 1 : 0;
+}
+
+static void
+cd9660_setup_root_node(void)
+{
+ cd9660_populate_iso_dir_record(diskStructure.rootNode->isoDirRecord,
+ 0, ISO_FLAG_DIRECTORY, 1, "\0");
+
+}
+
+/*********** SUPPORT FUNCTIONS ***********/
+static int
+cd9660_setup_volume_descriptors(void)
+{
+ /* Boot volume descriptor should come second */
+ int sector = 16;
+ /* For now, a fixed 2 : PVD and terminator */
+ volume_descriptor *temp, *t;
+
+ /* Set up the PVD */
+ if ((temp = malloc(sizeof(volume_descriptor))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
+ exit(1);
+ }
+
+ temp->volumeDescriptorData =
+ (unsigned char *)&diskStructure.primaryDescriptor;
+ temp->volumeDescriptorData[0] = ISO_VOLUME_DESCRIPTOR_PVD;
+ temp->volumeDescriptorData[6] = 1;
+ temp->sector = sector;
+ memcpy(temp->volumeDescriptorData + 1,
+ ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
+ diskStructure.firstVolumeDescriptor = temp;
+
+ sector++;
+ /* Set up boot support if enabled. BVD must reside in sector 17 */
+ if (diskStructure.is_bootable) {
+ if ((t = malloc(sizeof(volume_descriptor))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR(
+ "cd9660_setup_volume_descriptors");
+ exit(1);
+ }
+ if ((t->volumeDescriptorData = malloc(2048)) == NULL) {
+ CD9660_MEM_ALLOC_ERROR(
+ "cd9660_setup_volume_descriptors");
+ exit(1);
+ }
+ temp->next = t;
+ temp = t;
+ memset(t->volumeDescriptorData, 0, 2048);
+ t->sector = 17;
+ if (diskStructure.verbose_level > 0)
+ printf("Setting up boot volume descriptor\n");
+ cd9660_setup_boot_volume_descriptor(t);
+ sector++;
+ }
+
+ /* Set up the terminator */
+ if ((t = malloc(sizeof(volume_descriptor))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
+ exit(1);
+ }
+ if ((t->volumeDescriptorData = malloc(2048)) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
+ exit(1);
+ }
+
+ temp->next = t;
+ memset(t->volumeDescriptorData, 0, 2048);
+ t->volumeDescriptorData[0] = ISO_VOLUME_DESCRIPTOR_TERMINATOR;
+ t->next = 0;
+ t->volumeDescriptorData[6] = 1;
+ t->sector = sector;
+ memcpy(t->volumeDescriptorData + 1,
+ ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
+
+ sector++;
+ return sector;
+}
+
+#if 0
+/*
+ * Populate EAR at some point. Not required, but is used by NetBSD's
+ * cd9660 support
+ */
+static int
+cd9660_fill_extended_attribute_record(cd9660node *node)
+{
+ if ((node->isoExtAttributes =
+ malloc(sizeof(struct iso_extended_attributes))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_fill_extended_attribute_record");
+ exit(1);
+ };
+
+ return 1;
+}
+#endif
+
+static int
+cd9960_translate_node_common(cd9660node *newnode)
+{
+ time_t tim;
+ int test;
+ u_char flag;
+ char temp[ISO_FILENAME_MAXLENGTH_WITH_PADDING];
+
+ /* Now populate the isoDirRecord structure */
+ memset(temp, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING);
+
+ test = cd9660_convert_filename(newnode->node->name,
+ temp, !(S_ISDIR(newnode->node->type)));
+
+ flag = ISO_FLAG_CLEAR;
+ if (S_ISDIR(newnode->node->type))
+ flag |= ISO_FLAG_DIRECTORY;
+
+ cd9660_populate_iso_dir_record(newnode->isoDirRecord, 0,
+ flag, strlen(temp), temp);
+
+ /* Set the various dates */
+
+ /* If we want to use the current date and time */
+ time(&tim);
+
+ cd9660_time_915(newnode->isoDirRecord->date, tim);
+
+ cd9660_bothendian_dword(newnode->fileDataLength,
+ newnode->isoDirRecord->size);
+ /* If the file is a link, we want to set the size to 0 */
+ if (S_ISLNK(newnode->node->type))
+ newnode->fileDataLength = 0;
+
+ return 1;
+}
+
+/*
+ * Translate fsnode to cd9960node
+ * Translate filenames and other metadata, including dates, sizes,
+ * permissions, etc
+ * @param struct fsnode * The node generated by makefs
+ * @param struct cd9660node * The intermediate node to be written to
+ * @returns int 0 on failure, 1 on success
+ */
+static int
+cd9660_translate_node(fsnode *node, cd9660node *newnode)
+{
+ if (node == NULL) {
+ if (diskStructure.verbose_level > 0)
+ printf("cd9660_translate_node: NULL node passed, "
+ "returning\n");
+ return 0;
+ }
+ if ((newnode->isoDirRecord =
+ malloc(sizeof(iso_directory_record_cd9660))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_translate_node");
+ return 0;
+ }
+
+ /* Set the node pointer */
+ newnode->node = node;
+
+ /* Set the size */
+ if (!(S_ISDIR(node->type)))
+ newnode->fileDataLength = node->inode->st.st_size;
+
+ if (cd9960_translate_node_common(newnode) == 0)
+ return 0;
+
+ /* Finally, overwrite some of the values that are set by default */
+ cd9660_time_915(newnode->isoDirRecord->date, node->inode->st.st_mtime);
+
+ return 1;
+}
+
+/*
+ * Compares two ISO filenames
+ * @param const char * The first file name
+ * @param const char * The second file name
+ * @returns : -1 if first is less than second, 0 if they are the same, 1 if
+ * the second is greater than the first
+ */
+static int
+cd9660_compare_filename(const char *first, const char *second)
+{
+ /*
+ * This can be made more optimal once it has been tested
+ * (the extra character, for example, is for testing)
+ */
+
+ int p1 = 0;
+ int p2 = 0;
+ char c1, c2;
+ /* First, on the filename */
+
+ while (p1 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION-1
+ && p2 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION-1) {
+ c1 = first[p1];
+ c2 = second[p2];
+ if (c1 == '.' && c2 =='.')
+ break;
+ else if (c1 == '.') {
+ p2++;
+ c1 = ' ';
+ } else if (c2 == '.') {
+ p1++;
+ c2 = ' ';
+ } else {
+ p1++;
+ p2++;
+ }
+
+ if (c1 < c2)
+ return -1;
+ else if (c1 > c2) {
+ return 1;
+ }
+ }
+
+ if (first[p1] == '.' && second[p2] == '.') {
+ p1++;
+ p2++;
+ while (p1 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION - 1
+ && p2 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION - 1) {
+ c1 = first[p1];
+ c2 = second[p2];
+ if (c1 == ';' && c2 == ';')
+ break;
+ else if (c1 == ';') {
+ p2++;
+ c1 = ' ';
+ } else if (c2 == ';') {
+ p1++;
+ c2 = ' ';
+ } else {
+ p1++;
+ p2++;
+ }
+
+ if (c1 < c2)
+ return -1;
+ else if (c1 > c2)
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Insert a node into list with ISO sorting rules
+ * @param cd9660node * The head node of the list
+ * @param cd9660node * The node to be inserted
+ */
+static void
+cd9660_sorted_child_insert(cd9660node *parent, cd9660node *cn_new)
+{
+ int compare;
+ cd9660node *cn;
+ struct cd9660_children_head *head = &parent->cn_children;
+
+ /* TODO: Optimize? */
+ cn_new->parent = parent;
+
+ /*
+ * first will either be 0, the . or the ..
+ * if . or .., this means no other entry may be written before first
+ * if 0, the new node may be inserted at the head
+ */
+
+ TAILQ_FOREACH(cn, head, cn_next_child) {
+ /*
+ * Dont insert a node twice -
+ * that would cause an infinite loop
+ */
+ if (cn_new == cn)
+ return;
+
+ compare = cd9660_compare_filename(cn_new->isoDirRecord->name,
+ cn->isoDirRecord->name);
+
+ if (compare == 0)
+ compare = cd9660_compare_filename(cn_new->node->name,
+ cn->node->name);
+
+ if (compare < 0)
+ break;
+ }
+ if (cn == NULL)
+ TAILQ_INSERT_TAIL(head, cn_new, cn_next_child);
+ else
+ TAILQ_INSERT_BEFORE(cn, cn_new, cn_next_child);
+}
+
+/*
+ * Called After cd9660_sorted_child_insert
+ * handles file collisions by suffixing each filname with ~n
+ * where n represents the files respective place in the ordering
+ */
+static int
+cd9660_handle_collisions(cd9660node *colliding, int past)
+{
+ cd9660node *iter, *next, *prev;
+ int skip;
+ int delete_chars = 0;
+ int temp_past = past;
+ int temp_skip;
+ int flag = 0;
+ cd9660node *end_of_range;
+
+ for (iter = TAILQ_FIRST(&colliding->cn_children);
+ iter != NULL && (next = TAILQ_NEXT(iter, cn_next_child)) != NULL;) {
+ if (strcmp(iter->isoDirRecord->name,
+ next->isoDirRecord->name) != 0) {
+ iter = TAILQ_NEXT(iter, cn_next_child);
+ continue;
+ }
+ flag = 1;
+ temp_skip = skip = cd9660_count_collisions(iter);
+ end_of_range = iter;
+ while (temp_skip > 0) {
+ temp_skip--;
+ end_of_range = TAILQ_NEXT(end_of_range, cn_next_child);
+ }
+ temp_past = past;
+ while (temp_past > 0) {
+ if ((next = TAILQ_NEXT(end_of_range, cn_next_child)) != NULL)
+ end_of_range = next;
+ else if ((prev = TAILQ_PREV(iter, cd9660_children_head, cn_next_child)) != NULL)
+ iter = prev;
+ else
+ delete_chars++;
+ temp_past--;
+ }
+ skip += past;
+ iter = cd9660_rename_filename(iter, skip, delete_chars);
+ }
+ return flag;
+}
+
+
+static cd9660node *
+cd9660_rename_filename(cd9660node *iter, int num, int delete_chars)
+{
+ int i = 0;
+ int numbts, dot, semi, digit, digits, temp, powers, multiplier, count;
+ char *naming;
+ int maxlength;
+ char *tmp;
+
+ if (diskStructure.verbose_level > 0)
+ printf("Rename_filename called\n");
+
+ /* TODO : A LOT of chanes regarding 8.3 filenames */
+ if (diskStructure.isoLevel == 1)
+ maxlength = 8;
+ else if (diskStructure.isoLevel == 2)
+ maxlength = 31;
+ else
+ maxlength = ISO_FILENAME_MAXLENGTH_BEFORE_VERSION;
+
+ tmp = malloc(ISO_FILENAME_MAXLENGTH_WITH_PADDING);
+
+ while (i < num) {
+ powers = 1;
+ count = 0;
+ digits = 1;
+ multiplier = 1;
+ while (((int)(i / powers) ) >= 10) {
+ digits++;
+ powers = powers * 10;
+ }
+
+ naming = iter->o_name;
+
+ /*
+ while ((*naming != '.') && (*naming != ';')) {
+ naming++;
+ count++;
+ }
+ */
+
+ dot = -1;
+ semi = -1;
+ while (count < maxlength) {
+ if (*naming == '.')
+ dot = count;
+ else if (*naming == ';') {
+ semi = count;
+ break;
+ }
+ naming++;
+ count++;
+ }
+
+ if ((count + digits) < maxlength)
+ numbts = count;
+ else
+ numbts = maxlength - (digits);
+ numbts -= delete_chars;
+
+ /* 8.3 rules - keep the extension, add before the dot */
+
+ /*
+ * This code makes a bunch of assumptions.
+ * See if you can spot them all :)
+ */
+
+ /*
+ if (diskStructure.isoLevel == 1) {
+ numbts = 8 - digits - delete_chars;
+ if (dot < 0) {
+
+ } else {
+ if (dot < 8) {
+ memmove(&tmp[numbts],&tmp[dot],4);
+ }
+ }
+ }
+ */
+
+ /* (copying just the filename before the '.' */
+ memcpy(tmp, (iter->o_name), numbts);
+
+ /* adding the appropriate number following the name */
+ temp = i;
+ while (digits > 0) {
+ digit = (int)(temp / powers);
+ temp = temp - digit * powers;
+ sprintf(&tmp[numbts] , "%d", digit);
+ digits--;
+ numbts++;
+ powers = powers / 10;
+ }
+
+ while ((*naming != ';') && (numbts < maxlength)) {
+ tmp[numbts] = (*naming);
+ naming++;
+ numbts++;
+ }
+
+ tmp[numbts] = ';';
+ tmp[numbts+1] = '1';
+ tmp[numbts+2] = '\0';
+
+ /*
+ * now tmp has exactly the identifier
+ * we want so we'll copy it back to record
+ */
+ memcpy((iter->isoDirRecord->name), tmp, numbts + 3);
+
+ iter = TAILQ_NEXT(iter, cn_next_child);
+ i++;
+ }
+
+ free(tmp);
+ return iter;
+}
+
+/* Todo: Figure out why these functions are nec. */
+static void
+cd9660_copy_filenames(cd9660node *node)
+{
+ cd9660node *cn;
+
+ if (TAILQ_EMPTY(&node->cn_children))
+ return;
+
+ if (TAILQ_FIRST(&node->cn_children)->isoDirRecord == NULL) {
+ debug_print_tree(diskStructure.rootNode, 0);
+ exit(1);
+ }
+
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
+ cd9660_copy_filenames(cn);
+ memcpy(cn->o_name, cn->isoDirRecord->name,
+ ISO_FILENAME_MAXLENGTH_WITH_PADDING);
+ }
+}
+
+static void
+cd9660_sorting_nodes(cd9660node *node)
+{
+ cd9660node *cn;
+
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
+ cd9660_sorting_nodes(cn);
+ cd9660_sort_nodes(node);
+}
+
+/* XXX Bubble sort. */
+static void
+cd9660_sort_nodes(cd9660node *node)
+{
+ cd9660node *cn, *next;
+
+ do {
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
+ if ((next = TAILQ_NEXT(cn, cn_next_child)) == NULL)
+ return;
+ else if (strcmp(next->isoDirRecord->name,
+ cn->isoDirRecord->name) >= 0)
+ continue;
+ TAILQ_REMOVE(&node->cn_children, next, cn_next_child);
+ TAILQ_INSERT_BEFORE(cn, next, cn_next_child);
+ break;
+ }
+ } while (cn != NULL);
+}
+
+static int
+cd9660_count_collisions(cd9660node *copy)
+{
+ int count = 0;
+ cd9660node *iter, *next;
+
+ for (iter = copy;
+ (next = TAILQ_NEXT(iter, cn_next_child)) != NULL;
+ iter = next) {
+ if (cd9660_compare_filename(iter->isoDirRecord->name,
+ next->isoDirRecord->name) == 0)
+ count++;
+ else
+ return count;
+ }
+#if 0
+ if ((next = TAILQ_NEXT(iter, cn_next_child)) != NULL) {
+ printf("cd9660_recurse_on_collision: count is %i \n", count);
+ compare = cd9660_compare_filename(iter->isoDirRecord->name,
+ next->isoDirRecord->name);
+ if (compare == 0) {
+ count++;
+ return cd9660_recurse_on_collision(next, count);
+ } else
+ return count;
+ }
+#endif
+ return count;
+}
+
+static cd9660node *
+cd9660_rrip_move_directory(cd9660node *dir)
+{
+ char newname[9];
+ cd9660node *tfile;
+
+ /*
+ * This function needs to:
+ * 1) Create an empty virtual file in place of the old directory
+ * 2) Point the virtual file to the new directory
+ * 3) Point the relocated directory to its old parent
+ * 4) Move the directory specified by dir into rr_moved_dir,
+ * and rename it to "diskStructure.rock_ridge_move_count" (as a string)
+ */
+
+ /* First see if the moved directory even exists */
+ if (diskStructure.rr_moved_dir == NULL) {
+ diskStructure.rr_moved_dir =
+ cd9660_create_directory(ISO_RRIP_DEFAULT_MOVE_DIR_NAME,
+ diskStructure.rootNode, dir);
+ if (diskStructure.rr_moved_dir == NULL)
+ return 0;
+ }
+
+ /* Create a file with the same ORIGINAL name */
+ tfile = cd9660_create_file(dir->node->name, dir->parent, dir);
+ if (tfile == NULL)
+ return NULL;
+
+ diskStructure.rock_ridge_move_count++;
+ snprintf(newname, sizeof(newname), "%08i",
+ diskStructure.rock_ridge_move_count);
+
+ /* Point to old parent */
+ dir->rr_real_parent = dir->parent;
+
+ /* Place the placeholder file */
+ if (TAILQ_EMPTY(&dir->rr_real_parent->cn_children)) {
+ TAILQ_INSERT_HEAD(&dir->rr_real_parent->cn_children, tfile,
+ cn_next_child);
+ } else {
+ cd9660_sorted_child_insert(dir->rr_real_parent, tfile);
+ }
+
+ /* Point to new parent */
+ dir->parent = diskStructure.rr_moved_dir;
+
+ /* Point the file to the moved directory */
+ tfile->rr_relocated = dir;
+
+ /* Actually move the directory */
+ cd9660_sorted_child_insert(diskStructure.rr_moved_dir, dir);
+
+ /* TODO: Inherit permissions / ownership (basically the entire inode) */
+
+ /* Set the new name */
+ memset(dir->isoDirRecord->name, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING);
+ strncpy(dir->isoDirRecord->name, newname, 8);
+
+ return dir;
+}
+
+static int
+cd9660_add_dot_records(cd9660node *root)
+{
+ struct cd9660_children_head *head = &root->cn_children;
+ cd9660node *cn;
+
+ TAILQ_FOREACH(cn, head, cn_next_child) {
+ if ((cn->type & CD9660_TYPE_DIR) == 0)
+ continue;
+ /* Recursion first */
+ cd9660_add_dot_records(cn);
+ }
+ cd9660_create_special_directory(CD9660_TYPE_DOT, root);
+ cd9660_create_special_directory(CD9660_TYPE_DOTDOT, root);
+ return 1;
+}
+
+/*
+ * Convert node to cd9660 structure
+ * This function is designed to be called recursively on the root node of
+ * the filesystem
+ * Lots of recursion going on here, want to make sure it is efficient
+ * @param struct fsnode * The root node to be converted
+ * @param struct cd9660* The parent node (should not be NULL)
+ * @param int Current directory depth
+ * @param int* Running count of the number of directories that are being created
+ */
+static void
+cd9660_convert_structure(fsnode *root, cd9660node *parent_node, int level,
+ int *numDirectories, int *error)
+{
+ fsnode *iterator = root;
+ cd9660node *this_node;
+ int working_level;
+ int add;
+ int flag = 0;
+ int counter = 0;
+
+ /*
+ * Newer, more efficient method, reduces recursion depth
+ */
+ if (root == NULL) {
+ warnx("%s: root is null\n", __func__);
+ return;
+ }
+
+ /* Test for an empty directory - makefs still gives us the . record */
+ if ((S_ISDIR(root->type)) && (root->name[0] == '.')
+ && (root->name[1] == '\0')) {
+ root = root->next;
+ if (root == NULL)
+ return;
+ }
+ if ((this_node = cd9660_allocate_cd9660node()) == NULL) {
+ CD9660_MEM_ALLOC_ERROR(__func__);
+ }
+
+ /*
+ * To reduce the number of recursive calls, we will iterate over
+ * the next pointers to the right.
+ */
+ while (iterator != NULL) {
+ add = 1;
+ /*
+ * Increment the directory count if this is a directory
+ * Ignore "." entries. We will generate them later
+ */
+ if (!S_ISDIR(iterator->type) ||
+ strcmp(iterator->name, ".") != 0) {
+
+ /* Translate the node, including its filename */
+ this_node->parent = parent_node;
+ cd9660_translate_node(iterator, this_node);
+ this_node->level = level;
+
+ if (S_ISDIR(iterator->type)) {
+ (*numDirectories)++;
+ this_node->type = CD9660_TYPE_DIR;
+ working_level = level + 1;
+
+ /*
+ * If at level 8, directory would be at 8
+ * and have children at 9 which is not
+ * allowed as per ISO spec
+ */
+ if (level == 8) {
+ if ((!diskStructure.allow_deep_trees) &&
+ (!diskStructure.rock_ridge_enabled)) {
+ warnx("error: found entry "
+ "with depth greater "
+ "than 8.");
+ (*error) = 1;
+ return;
+ } else if (diskStructure.
+ rock_ridge_enabled) {
+ working_level = 3;
+ /*
+ * Moved directory is actually
+ * at level 2.
+ */
+ this_node->level =
+ working_level - 1;
+ if (cd9660_rrip_move_directory(
+ this_node) == 0) {
+ warnx("Failure in "
+ "cd9660_rrip_"
+ "move_directory"
+ );
+ (*error) = 1;
+ return;
+ }
+ add = 0;
+ }
+ }
+
+ /* Do the recursive call on the children */
+ if (iterator->child != 0) {
+ cd9660_convert_structure(
+ iterator->child, this_node,
+ working_level,
+ numDirectories, error);
+
+ if ((*error) == 1) {
+ warnx("%s: Error on recursive "
+ "call", __func__);
+ return;
+ }
+ }
+
+ } else {
+ /* Only directories should have children */
+ assert(iterator->child == NULL);
+
+ this_node->type = CD9660_TYPE_FILE;
+ }
+
+ /*
+ * Finally, do a sorted insert
+ */
+ if (add) {
+ cd9660_sorted_child_insert(
+ parent_node, this_node);
+ }
+
+ /*Allocate new temp_node */
+ if (iterator->next != 0) {
+ this_node = cd9660_allocate_cd9660node();
+ if (this_node == NULL)
+ CD9660_MEM_ALLOC_ERROR(__func__);
+ }
+ }
+ iterator = iterator->next;
+ }
+
+ /* cd9660_handle_collisions(first_node); */
+
+ /* TODO: need cleanup */
+ cd9660_copy_filenames(parent_node);
+
+ do {
+ flag = cd9660_handle_collisions(parent_node, counter);
+ counter++;
+ cd9660_sorting_nodes(parent_node);
+ } while ((flag == 1) && (counter < 100));
+}
+
+/*
+ * Clean up the cd9660node tree
+ * This is designed to be called recursively on the root node
+ * @param struct cd9660node *root The node to free
+ * @returns void
+ */
+static void
+cd9660_free_structure(cd9660node *root)
+{
+ cd9660node *cn;
+
+ while ((cn = TAILQ_FIRST(&root->cn_children)) != NULL) {
+ TAILQ_REMOVE(&root->cn_children, cn, cn_next_child);
+ cd9660_free_structure(cn);
+ }
+ free(root);
+}
+
+/*
+ * Be a little more memory conservative:
+ * instead of having the TAILQ_ENTRY as part of the cd9660node,
+ * just create a temporary structure
+ */
+struct ptq_entry
+{
+ TAILQ_ENTRY(ptq_entry) ptq;
+ cd9660node *node;
+} *n;
+
+#define PTQUEUE_NEW(n,s,r,t){\
+ n = malloc(sizeof(struct s)); \
+ if (n == NULL) \
+ return r; \
+ n->node = t;\
+}
+
+/*
+ * Generate the path tables
+ * The specific implementation of this function is left as an exercise to the
+ * programmer. It could be done recursively. Make sure you read how the path
+ * table has to be laid out, it has levels.
+ * @param struct iso9660_disk *disk The disk image
+ * @returns int The number of built path tables (between 1 and 4), 0 on failure
+ */
+static int
+cd9660_generate_path_table(void)
+{
+ cd9660node *cn, *dirNode = diskStructure.rootNode;
+ cd9660node *last = dirNode;
+ int pathTableSize = 0; /* computed as we go */
+ int counter = 1; /* root gets a count of 0 */
+ int parentRecNum = 0; /* root's parent is '0' */
+
+ TAILQ_HEAD(cd9660_pt_head, ptq_entry) pt_head;
+ TAILQ_INIT(&pt_head);
+
+ PTQUEUE_NEW(n, ptq_entry, -1, diskStructure.rootNode);
+
+ /* Push the root node */
+ TAILQ_INSERT_HEAD(&pt_head, n, ptq);
+
+ /* Breadth-first traversal of file structure */
+ while (pt_head.tqh_first != 0) {
+ n = pt_head.tqh_first;
+ dirNode = n->node;
+ TAILQ_REMOVE(&pt_head, pt_head.tqh_first, ptq);
+ free(n);
+
+ /* Update the size */
+ pathTableSize += ISO_PATHTABLE_ENTRY_BASESIZE
+ + dirNode->isoDirRecord->name_len[0]+
+ (dirNode->isoDirRecord->name_len[0] % 2 == 0 ? 0 : 1);
+ /* includes the padding bit */
+
+ dirNode->ptnumber=counter;
+ if (dirNode != last) {
+ last->ptnext = dirNode;
+ dirNode->ptprev = last;
+ }
+ last = dirNode;
+
+ parentRecNum = 1;
+ if (dirNode->parent != 0)
+ parentRecNum = dirNode->parent->ptnumber;
+
+ /* Push children onto queue */
+ TAILQ_FOREACH(cn, &dirNode->cn_children, cn_next_child) {
+ /*
+ * Dont add the DOT and DOTDOT types to the path
+ * table.
+ */
+ if ((cn->type != CD9660_TYPE_DOT)
+ && (cn->type != CD9660_TYPE_DOTDOT)) {
+
+ if (S_ISDIR(cn->node->type)) {
+ PTQUEUE_NEW(n, ptq_entry, -1, cn);
+ TAILQ_INSERT_TAIL(&pt_head, n, ptq);
+ }
+ }
+ }
+ counter++;
+ }
+ return pathTableSize;
+}
+
+void
+cd9660_compute_full_filename(cd9660node *node, char *buf, int level)
+{
+ cd9660node *parent;
+
+ parent = (node->rr_real_parent == NULL ?
+ node->parent : node->rr_real_parent);
+ if (parent != NULL) {
+ cd9660_compute_full_filename(parent, buf, level + 1);
+ strcat(buf, node->node->name);
+ } else {
+ /* We are at the root */
+ strcat(buf, diskStructure.rootFilesystemPath);
+ if (buf[strlen(buf) - 1] == '/')
+ buf[strlen(buf) - 1] = '\0';
+ }
+
+ if (level != 0)
+ strcat(buf, "/");
+}
+
+/* NEW filename conversion method */
+typedef int(*cd9660_filename_conversion_functor)(const char *, char *, int);
+
+
+/*
+ * TODO: These two functions are almost identical.
+ * Some code cleanup is possible here
+ *
+ * XXX bounds checking!
+ */
+static int
+cd9660_level1_convert_filename(const char *oldname, char *newname, int is_file)
+{
+ /*
+ * ISO 9660 : 10.1
+ * File Name shall not contain more than 8 d or d1 characters
+ * File Name Extension shall not contain more than 3 d or d1 characters
+ * Directory Identifier shall not contain more than 8 d or d1 characters
+ */
+ int namelen = 0;
+ int extlen = 0;
+ int found_ext = 0;
+
+ while (*oldname != '\0') {
+ /* Handle period first, as it is special */
+ if (*oldname == '.') {
+ if (found_ext) {
+ *newname++ = '_';
+ extlen ++;
+ }
+ else {
+ *newname++ = '.';
+ found_ext = 1;
+ }
+ } else {
+ /* cut RISC OS file type off ISO name */
+ if (diskStructure.archimedes_enabled &&
+ *oldname == ',' && strlen(oldname) == 4)
+ break;
+ /* Enforce 12.3 / 8 */
+ if (((namelen == 8) && !found_ext) ||
+ (found_ext && extlen == 3)) {
+ break;
+ }
+
+ if (islower((unsigned char)*oldname))
+ *newname++ = toupper((unsigned char)*oldname);
+ else if (isupper((unsigned char)*oldname)
+ || isdigit((unsigned char)*oldname))
+ *newname++ = *oldname;
+ else
+ *newname++ = '_';
+
+ if (found_ext)
+ extlen++;
+ else
+ namelen++;
+ }
+ oldname ++;
+ }
+ if (is_file) {
+ if (!found_ext && !diskStructure.omit_trailing_period)
+ *newname++ = '.';
+ /* Add version */
+ sprintf(newname, ";%i", 1);
+ }
+ return namelen + extlen + found_ext;
+}
+
+/* XXX bounds checking! */
+static int
+cd9660_level2_convert_filename(const char *oldname, char *newname, int is_file)
+{
+ /*
+ * ISO 9660 : 7.5.1
+ * File name : 0+ d or d1 characters
+ * separator 1 (.)
+ * File name extension : 0+ d or d1 characters
+ * separator 2 (;)
+ * File version number (5 characters, 1-32767)
+ * 1 <= Sum of File name and File name extension <= 30
+ */
+ int namelen = 0;
+ int extlen = 0;
+ int found_ext = 0;
+
+ while (*oldname != '\0') {
+ /* Handle period first, as it is special */
+ if (*oldname == '.') {
+ if (found_ext) {
+ if (diskStructure.allow_multidot) {
+ *newname++ = '.';
+ } else {
+ *newname++ = '_';
+ }
+ extlen ++;
+ }
+ else {
+ *newname++ = '.';
+ found_ext = 1;
+ }
+ } else {
+ /* cut RISC OS file type off ISO name */
+ if (diskStructure.archimedes_enabled &&
+ *oldname == ',' && strlen(oldname) == 4)
+ break;
+ if ((namelen + extlen) == 30)
+ break;
+
+ if (islower((unsigned char)*oldname))
+ *newname++ = toupper((unsigned char)*oldname);
+ else if (isupper((unsigned char)*oldname) ||
+ isdigit((unsigned char)*oldname))
+ *newname++ = *oldname;
+ else if (diskStructure.allow_multidot &&
+ *oldname == '.') {
+ *newname++ = '.';
+ } else {
+ *newname++ = '_';
+ }
+
+ if (found_ext)
+ extlen++;
+ else
+ namelen++;
+ }
+ oldname ++;
+ }
+ if (is_file) {
+ if (!found_ext && !diskStructure.omit_trailing_period)
+ *newname++ = '.';
+ /* Add version */
+ sprintf(newname, ";%i", 1);
+ }
+ return namelen + extlen + found_ext;
+}
+
+#if 0
+static int
+cd9660_joliet_convert_filename(const char *oldname, char *newname, int is_file)
+{
+ /* TODO: implement later, move to cd9660_joliet.c ?? */
+}
+#endif
+
+
+/*
+ * Convert a file name to ISO compliant file name
+ * @param char * oldname The original filename
+ * @param char ** newname The new file name, in the appropriate character
+ * set and of appropriate length
+ * @param int 1 if file, 0 if directory
+ * @returns int The length of the new string
+ */
+static int
+cd9660_convert_filename(const char *oldname, char *newname, int is_file)
+{
+ /* NEW */
+ cd9660_filename_conversion_functor conversion_function = 0;
+ if (diskStructure.isoLevel == 1)
+ conversion_function = &cd9660_level1_convert_filename;
+ else if (diskStructure.isoLevel == 2)
+ conversion_function = &cd9660_level2_convert_filename;
+ return (*conversion_function)(oldname, newname, is_file);
+}
+
+int
+cd9660_compute_record_size(cd9660node *node)
+{
+ int size = node->isoDirRecord->length[0];
+
+ if (diskStructure.rock_ridge_enabled)
+ size += node->susp_entry_size;
+ size += node->su_tail_size;
+ size += size & 1; /* Ensure length of record is even. */
+ assert(size <= 254);
+ return size;
+}
+
+static void
+cd9660_populate_dot_records(cd9660node *node)
+{
+ node->dot_record->fileDataSector = node->fileDataSector;
+ memcpy(node->dot_record->isoDirRecord,node->isoDirRecord, 34);
+ node->dot_record->isoDirRecord->name_len[0] = 1;
+ node->dot_record->isoDirRecord->name[0] = 0;
+ node->dot_record->isoDirRecord->name[1] = 0;
+ node->dot_record->isoDirRecord->length[0] = 34;
+ node->dot_record->fileRecordSize =
+ cd9660_compute_record_size(node->dot_record);
+
+ if (node == diskStructure.rootNode) {
+ node->dot_dot_record->fileDataSector = node->fileDataSector;
+ memcpy(node->dot_dot_record->isoDirRecord,node->isoDirRecord,
+ 34);
+ } else {
+ node->dot_dot_record->fileDataSector =
+ node->parent->fileDataSector;
+ memcpy(node->dot_dot_record->isoDirRecord,
+ node->parent->isoDirRecord,34);
+ }
+ node->dot_dot_record->isoDirRecord->name_len[0] = 1;
+ node->dot_dot_record->isoDirRecord->name[0] = 1;
+ node->dot_dot_record->isoDirRecord->name[1] = 0;
+ node->dot_dot_record->isoDirRecord->length[0] = 34;
+ node->dot_dot_record->fileRecordSize =
+ cd9660_compute_record_size(node->dot_dot_record);
+}
+
+/*
+ * @param struct cd9660node *node The node
+ * @param int The offset (in bytes) - SHOULD align to the beginning of a sector
+ * @returns int The total size of files and directory entries (should be
+ * a multiple of sector size)
+*/
+static int64_t
+cd9660_compute_offsets(cd9660node *node, int64_t startOffset)
+{
+ /*
+ * This function needs to compute the size of directory records and
+ * runs, file lengths, and set the appropriate variables both in
+ * cd9660node and isoDirEntry
+ */
+ int64_t used_bytes = 0;
+ int64_t current_sector_usage = 0;
+ cd9660node *child;
+ fsinode *inode;
+ int64_t r;
+
+ assert(node != NULL);
+
+
+ /*
+ * NOTE : There needs to be some special case detection for
+ * the "real root" node, since for it, node->node is undefined
+ */
+
+ node->fileDataSector = -1;
+
+ if (node->type & CD9660_TYPE_DIR) {
+ node->fileRecordSize = cd9660_compute_record_size(node);
+ /*Set what sector this directory starts in*/
+ node->fileDataSector =
+ CD9660_BLOCKS(diskStructure.sectorSize,startOffset);
+
+ cd9660_bothendian_dword(node->fileDataSector,
+ node->isoDirRecord->extent);
+
+ /*
+ * First loop over children, need to know the size of
+ * their directory records
+ */
+ node->fileSectorsUsed = 1;
+ TAILQ_FOREACH(child, &node->cn_children, cn_next_child) {
+ node->fileDataLength +=
+ cd9660_compute_record_size(child);
+ if ((cd9660_compute_record_size(child) +
+ current_sector_usage) >=
+ diskStructure.sectorSize) {
+ current_sector_usage = 0;
+ node->fileSectorsUsed++;
+ }
+
+ current_sector_usage +=
+ cd9660_compute_record_size(child);
+ }
+
+ cd9660_bothendian_dword(node->fileSectorsUsed *
+ diskStructure.sectorSize,node->isoDirRecord->size);
+
+ /*
+ * This should point to the sector after the directory
+ * record (or, the first byte in that sector)
+ */
+ used_bytes += node->fileSectorsUsed * diskStructure.sectorSize;
+
+ for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child);
+ child != NULL; child = TAILQ_NEXT(child, cn_next_child)) {
+ /* Directories need recursive call */
+ if (S_ISDIR(child->node->type)) {
+ r = cd9660_compute_offsets(child,
+ used_bytes + startOffset);
+
+ if (r != -1)
+ used_bytes += r;
+ else
+ return -1;
+ }
+ }
+
+ /* Explicitly set the . and .. records */
+ cd9660_populate_dot_records(node);
+
+ /* Finally, do another iteration to write the file data*/
+ for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child);
+ child != NULL;
+ child = TAILQ_NEXT(child, cn_next_child)) {
+ /* Files need extent set */
+ if (S_ISDIR(child->node->type))
+ continue;
+ child->fileRecordSize =
+ cd9660_compute_record_size(child);
+
+ child->fileSectorsUsed =
+ CD9660_BLOCKS(diskStructure.sectorSize,
+ child->fileDataLength);
+
+ inode = child->node->inode;
+ if ((inode->flags & FI_ALLOCATED) == 0) {
+ inode->ino =
+ CD9660_BLOCKS(diskStructure.sectorSize,
+ used_bytes + startOffset);
+ inode->flags |= FI_ALLOCATED;
+ used_bytes += child->fileSectorsUsed *
+ diskStructure.sectorSize;
+ } else {
+ INODE_WARNX(("%s: already allocated inode %d "
+ "data sectors at %" PRIu32, __func__,
+ (int)inode->st.st_ino, inode->ino));
+ }
+ child->fileDataSector = inode->ino;
+ cd9660_bothendian_dword(child->fileDataSector,
+ child->isoDirRecord->extent);
+ }
+ }
+
+ return used_bytes;
+}
+
+#if 0
+/* Might get rid of this func */
+static int
+cd9660_copy_stat_info(cd9660node *from, cd9660node *to, int file)
+{
+ to->node->inode->st.st_dev = 0;
+ to->node->inode->st.st_ino = 0;
+ to->node->inode->st.st_size = 0;
+ to->node->inode->st.st_blksize = from->node->inode->st.st_blksize;
+ to->node->inode->st.st_atime = from->node->inode->st.st_atime;
+ to->node->inode->st.st_mtime = from->node->inode->st.st_mtime;
+ to->node->inode->st.st_ctime = from->node->inode->st.st_ctime;
+ to->node->inode->st.st_uid = from->node->inode->st.st_uid;
+ to->node->inode->st.st_gid = from->node->inode->st.st_gid;
+ to->node->inode->st.st_mode = from->node->inode->st.st_mode;
+ /* Clear out type */
+ to->node->inode->st.st_mode = to->node->inode->st.st_mode & ~(S_IFMT);
+ if (file)
+ to->node->inode->st.st_mode |= S_IFREG;
+ else
+ to->node->inode->st.st_mode |= S_IFDIR;
+ return 1;
+}
+#endif
+
+static cd9660node *
+cd9660_create_virtual_entry(const char *name, cd9660node *parent, int file,
+ int insert)
+{
+ cd9660node *temp;
+ fsnode * tfsnode;
+
+ assert(parent != NULL);
+
+ temp = cd9660_allocate_cd9660node();
+ if (temp == NULL)
+ return NULL;
+
+ if ((tfsnode = malloc(sizeof(fsnode))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
+ return NULL;
+ }
+
+ /* Assume for now name is a valid length */
+ if ((tfsnode->name = malloc(strlen(name) + 1)) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
+ return NULL;
+ }
+
+ if ((temp->isoDirRecord =
+ malloc(sizeof(iso_directory_record_cd9660))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
+ return NULL;
+ }
+
+ strcpy(tfsnode->name, name);
+
+ cd9660_convert_filename(tfsnode->name, temp->isoDirRecord->name, file);
+
+ temp->node = tfsnode;
+ temp->parent = parent;
+
+ if (insert) {
+ if (temp->parent != NULL) {
+ temp->level = temp->parent->level + 1;
+ if (!TAILQ_EMPTY(&temp->parent->cn_children))
+ cd9660_sorted_child_insert(temp->parent, temp);
+ else
+ TAILQ_INSERT_HEAD(&temp->parent->cn_children,
+ temp, cn_next_child);
+ }
+ }
+
+ if (parent->node != NULL) {
+ tfsnode->type = parent->node->type;
+ }
+
+ /* Clear out file type bits */
+ tfsnode->type &= ~(S_IFMT);
+ if (file)
+ tfsnode->type |= S_IFREG;
+ else
+ tfsnode->type |= S_IFDIR;
+
+ /* Indicate that there is no spec entry (inode) */
+ tfsnode->flags &= ~(FSNODE_F_HASSPEC);
+#if 0
+ cd9660_copy_stat_info(parent, temp, file);
+#endif
+ return temp;
+}
+
+static cd9660node *
+cd9660_create_file(const char * name, cd9660node *parent, cd9660node *me)
+{
+ cd9660node *temp;
+
+ temp = cd9660_create_virtual_entry(name,parent,1,1);
+ if (temp == NULL)
+ return NULL;
+
+ temp->fileDataLength = 0;
+
+ temp->type = CD9660_TYPE_FILE | CD9660_TYPE_VIRTUAL;
+
+ if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL)
+ return NULL;
+ *temp->node->inode = *me->node->inode;
+
+ if (cd9960_translate_node_common(temp) == 0)
+ return NULL;
+ return temp;
+}
+
+/*
+ * Create a new directory which does not exist on disk
+ * @param const char * name The name to assign to the directory
+ * @param const char * parent Pointer to the parent directory
+ * @returns cd9660node * Pointer to the new directory
+ */
+static cd9660node *
+cd9660_create_directory(const char *name, cd9660node *parent, cd9660node *me)
+{
+ cd9660node *temp;
+
+ temp = cd9660_create_virtual_entry(name,parent,0,1);
+ if (temp == NULL)
+ return NULL;
+ temp->node->type |= S_IFDIR;
+
+ temp->type = CD9660_TYPE_DIR | CD9660_TYPE_VIRTUAL;
+
+ if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL)
+ return NULL;
+ *temp->node->inode = *me->node->inode;
+
+ if (cd9960_translate_node_common(temp) == 0)
+ return NULL;
+ return temp;
+}
+
+static cd9660node *
+cd9660_create_special_directory(u_char type, cd9660node *parent)
+{
+ cd9660node *temp, *first;
+ char na[2];
+
+ assert(parent != NULL);
+
+ if (type == CD9660_TYPE_DOT)
+ na[0] = 0;
+ else if (type == CD9660_TYPE_DOTDOT)
+ na[0] = 1;
+ else
+ return 0;
+
+ na[1] = 0;
+ if ((temp = cd9660_create_virtual_entry(na, parent, 0, 0)) == NULL)
+ return NULL;
+
+ temp->parent = parent;
+ temp->type = type;
+ temp->isoDirRecord->length[0] = 34;
+ /* Dot record is always first */
+ if (type == CD9660_TYPE_DOT) {
+ parent->dot_record = temp;
+ TAILQ_INSERT_HEAD(&parent->cn_children, temp, cn_next_child);
+ /* DotDot should be second */
+ } else if (type == CD9660_TYPE_DOTDOT) {
+ parent->dot_dot_record = temp;
+ /*
+ * If the first child is the dot record, insert
+ * this second. Otherwise, insert it at the head.
+ */
+ if ((first = TAILQ_FIRST(&parent->cn_children)) == NULL ||
+ (first->type & CD9660_TYPE_DOT) == 0) {
+ TAILQ_INSERT_HEAD(&parent->cn_children, temp,
+ cn_next_child);
+ } else {
+ TAILQ_INSERT_AFTER(&parent->cn_children, first, temp,
+ cn_next_child);
+ }
+ }
+
+ return temp;
+}
+
+int
+cd9660_add_generic_bootimage(const char *bootimage)
+{
+ struct stat stbuf;
+
+ assert(bootimage != NULL);
+
+ if (*bootimage == '\0') {
+ warnx("Error: Boot image must be a filename");
+ return 0;
+ }
+
+ if ((diskStructure.generic_bootimage = strdup(bootimage)) == NULL) {
+ warn("%s: strdup", __func__);
+ return 0;
+ }
+
+ /* Get information about the file */
+ if (lstat(diskStructure.generic_bootimage, &stbuf) == -1)
+ err(EXIT_FAILURE, "%s: lstat(\"%s\")", __func__,
+ diskStructure.generic_bootimage);
+
+ if (stbuf.st_size > 32768) {
+ warnx("Error: Boot image must be no greater than 32768 bytes");
+ return 0;
+ }
+
+ if (diskStructure.verbose_level > 0) {
+ printf("Generic boot image image has size %lld\n",
+ (long long)stbuf.st_size);
+ }
+
+ diskStructure.has_generic_bootimage = 1;
+
+ return 1;
+}
diff --git a/usr.sbin/makefs/cd9660.h b/usr.sbin/makefs/cd9660.h
new file mode 100644
index 0000000..16c0d64
--- /dev/null
+++ b/usr.sbin/makefs/cd9660.h
@@ -0,0 +1,364 @@
+/* $NetBSD: cd9660.h,v 1.15 2010/10/27 18:51:34 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (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$
+ */
+
+#ifndef _MAKEFS_CD9660_H
+#define _MAKEFS_CD9660_H
+
+#include <inttypes.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <limits.h>
+#include <sys/queue.h>
+#include <sys/param.h>
+
+#include "makefs.h"
+#include "iso.h"
+#include "iso_rrip.h"
+#include "cd9660/cd9660_eltorito.h"
+
+#ifdef DEBUG
+#define INODE_WARNX(__x) warnx __x
+#else /* DEBUG */
+#define INODE_WARNX(__x)
+#endif /* DEBUG */
+
+#define CD9660MAXPATH 4096
+
+#define ISO_STRING_FILTER_NONE = 0x00
+#define ISO_STRING_FILTER_DCHARS = 0x01
+#define ISO_STRING_FILTER_ACHARS = 0x02
+
+/*
+Extended preferences type, in the spirit of what makefs gives us (only ints)
+*/
+typedef struct {
+ const char *shortName; /* Short option */
+ const char *name; /* option name */
+ char *value; /* where to stuff the value */
+ int minLength; /* minimum for value */
+ int maxLength; /* maximum for value */
+ const char *desc; /* option description */
+ int filterFlags;
+} string_option_t;
+
+/******** STRUCTURES **********/
+
+/*Defaults*/
+#define ISO_DEFAULT_VOLUMEID "MAKEFS_CD9660_IMAGE"
+#define ISO_DEFAULT_APPID "MAKEFS"
+#define ISO_DEFAULT_PUBLISHER "MAKEFS"
+#define ISO_DEFAULT_PREPARER "MAKEFS"
+
+#define ISO_VOLUME_DESCRIPTOR_STANDARD_ID "CD001"
+#define ISO_VOLUME_DESCRIPTOR_BOOT 0
+#define ISO_VOLUME_DESCRIPTOR_PVD 1
+#define ISO_VOLUME_DESCRIPTOR_TERMINATOR 255
+
+/*30 for name and extension, as well as version number and padding bit*/
+#define ISO_FILENAME_MAXLENGTH_BEFORE_VERSION 30
+#define ISO_FILENAME_MAXLENGTH 36
+#define ISO_FILENAME_MAXLENGTH_WITH_PADDING 37
+
+#define ISO_FLAG_CLEAR 0x00
+#define ISO_FLAG_HIDDEN 0x01
+#define ISO_FLAG_DIRECTORY 0x02
+#define ISO_FLAG_ASSOCIATED 0x04
+#define ISO_FLAG_PERMISSIONS 0x08
+#define ISO_FLAG_RESERVED5 0x10
+#define ISO_FLAG_RESERVED6 0x20
+#define ISO_FLAG_FINAL_RECORD 0x40
+
+#define ISO_PATHTABLE_ENTRY_BASESIZE 8
+
+#define ISO_RRIP_DEFAULT_MOVE_DIR_NAME "RR_MOVED"
+#define RRIP_DEFAULT_MOVE_DIR_NAME ".rr_moved"
+
+#define CD9660_BLOCKS(__sector_size, __bytes) \
+ howmany((__bytes), (__sector_size))
+
+#define CD9660_MEM_ALLOC_ERROR(_F) \
+ err(EXIT_FAILURE, "%s, %s l. %d", _F, __FILE__, __LINE__)
+
+#define CD9660_IS_COMMAND_ARG_DUAL(var,short,long)\
+ (strcmp((var),(short)) == 0) || (strcmp((var),(long))==0)
+
+#define CD9660_IS_COMMAND_ARG(var,arg)\
+ (strcmp((var),(arg)) == 0)
+
+#define CD9660_TYPE_FILE 0x01
+#define CD9660_TYPE_DIR 0x02
+#define CD9660_TYPE_DOT 0x04
+#define CD9660_TYPE_DOTDOT 0x08
+#define CD9660_TYPE_VIRTUAL 0x80
+
+#define CD9660_INODE_HASH_SIZE 1024
+#define CD9660_SECTOR_SIZE 2048
+
+#define CD9660_END_PADDING 150
+
+/* Slight modification of the ISO structure in iso.h */
+typedef struct _iso_directory_record_cd9660 {
+ u_char length [ISODCL (1, 1)]; /* 711 */
+ u_char ext_attr_length [ISODCL (2, 2)]; /* 711 */
+ u_char extent [ISODCL (3, 10)]; /* 733 */
+ u_char size [ISODCL (11, 18)]; /* 733 */
+ u_char date [ISODCL (19, 25)]; /* 7 by 711 */
+ u_char flags [ISODCL (26, 26)];
+ u_char file_unit_size [ISODCL (27, 27)]; /* 711 */
+ u_char interleave [ISODCL (28, 28)]; /* 711 */
+ u_char volume_sequence_number [ISODCL (29, 32)]; /* 723 */
+ u_char name_len [ISODCL (33, 33)]; /* 711 */
+ char name [ISO_FILENAME_MAXLENGTH_WITH_PADDING];
+} iso_directory_record_cd9660;
+
+/* TODO: Lots of optimization of this structure */
+typedef struct _cd9660node {
+ u_char type;/* Used internally */
+ /* Tree structure */
+ struct _cd9660node *parent; /* parent (NULL if root) */
+ TAILQ_HEAD(cd9660_children_head, _cd9660node) cn_children;
+ TAILQ_ENTRY(_cd9660node) cn_next_child;
+
+ struct _cd9660node *dot_record; /* For directories, used mainly in RRIP */
+ struct _cd9660node *dot_dot_record;
+
+ fsnode *node; /* pointer to fsnode */
+ struct _iso_directory_record_cd9660 *isoDirRecord;
+ struct iso_extended_attributes *isoExtAttributes;
+
+ /***** SIZE CALCULATION *****/
+ /*already stored in isoDirRecord, but this is an int version, and will be
+ copied to isoDirRecord on writing*/
+ uint32_t fileDataSector;
+
+ /*
+ * same thing, though some notes:
+ * If a file, this is the file size
+ * If a directory, this is the size of all its children's
+ * directory records
+ * plus necessary padding
+ */
+ int64_t fileDataLength;
+
+ int64_t fileSectorsUsed;
+ int fileRecordSize;/*copy of a variable, int for quicker calculations*/
+
+ /* Old name, used for renaming - needs to be optimized but low priority */
+ char o_name [ISO_FILENAME_MAXLENGTH_WITH_PADDING];
+
+ /***** SPACE RESERVED FOR EXTENSIONS *****/
+ /* For memory efficiency's sake - we should move this to a separate struct
+ and point to null if not needed */
+ /* For Rock Ridge */
+ struct _cd9660node *rr_real_parent, *rr_relocated;
+
+ int64_t susp_entry_size;
+ int64_t susp_dot_entry_size;
+ int64_t susp_dot_dot_entry_size;
+
+ /* Continuation area stuff */
+ int64_t susp_entry_ce_start;
+ int64_t susp_dot_ce_start;
+ int64_t susp_dot_dot_ce_start;
+
+ int64_t susp_entry_ce_length;
+ int64_t susp_dot_ce_length;
+ int64_t susp_dot_dot_ce_length;
+
+ /* Data to put at the end of the System Use field */
+ int64_t su_tail_size;
+ char *su_tail_data;
+
+ /*** PATH TABLE STUFF ***/
+ int level; /*depth*/
+ int ptnumber;
+ struct _cd9660node *ptnext, *ptprev, *ptlast;
+
+ /* SUSP entries */
+ TAILQ_HEAD(susp_linked_list, ISO_SUSP_ATTRIBUTES) head;
+} cd9660node;
+
+typedef struct _path_table_entry
+{
+ u_char length[ISODCL (1, 1)];
+ u_char extended_attribute_length[ISODCL (2, 2)];
+ u_char first_sector[ISODCL (3, 6)];
+ u_char parent_number[ISODCL (7, 8)];
+ u_char name[ISO_FILENAME_MAXLENGTH_WITH_PADDING];
+} path_table_entry;
+
+typedef struct _volume_descriptor
+{
+ u_char *volumeDescriptorData; /*ALWAYS 2048 bytes long*/
+ int64_t sector;
+ struct _volume_descriptor *next;
+} volume_descriptor;
+
+typedef struct _iso9660_disk {
+ int sectorSize;
+ struct iso_primary_descriptor primaryDescriptor;
+ struct iso_supplementary_descriptor supplementaryDescriptor;
+
+ volume_descriptor *firstVolumeDescriptor;
+
+ cd9660node *rootNode;
+
+ const char *rootFilesystemPath;
+
+ /* Important sector numbers here */
+ /* primaryDescriptor.type_l_path_table*/
+ int64_t primaryBigEndianTableSector;
+
+ /* primaryDescriptor.type_m_path_table*/
+ int64_t primaryLittleEndianTableSector;
+
+ /* primaryDescriptor.opt_type_l_path_table*/
+ int64_t secondaryBigEndianTableSector;
+
+ /* primaryDescriptor.opt_type_m_path_table*/
+ int64_t secondaryLittleEndianTableSector;
+
+ /* primaryDescriptor.path_table_size*/
+ int pathTableLength;
+ int64_t dataFirstSector;
+
+ int64_t totalSectors;
+ /* OPTIONS GO HERE */
+ int isoLevel;
+
+ int include_padding_areas;
+
+ int follow_sym_links;
+ int verbose_level;
+ int displayHelp;
+ int keep_bad_images;
+
+ /* SUSP options and variables */
+ int64_t susp_continuation_area_start_sector;
+ int64_t susp_continuation_area_size;
+ int64_t susp_continuation_area_current_free;
+
+ int rock_ridge_enabled;
+ /* Other Rock Ridge Variables */
+ char *rock_ridge_renamed_dir_name;
+ int rock_ridge_move_count;
+ cd9660node *rr_moved_dir;
+
+ int archimedes_enabled;
+
+ /* Spec breaking options */
+ u_char allow_deep_trees;
+ u_char allow_start_dot;
+ u_char allow_max_name; /* Allow 37 char filenames*/
+ u_char allow_illegal_chars; /* ~, !, # */
+ u_char allow_lowercase;
+ u_char allow_multidot;
+ u_char omit_trailing_period;
+
+ /* BOOT INFORMATION HERE */
+ int has_generic_bootimage; /* Default to 0 */
+ char *generic_bootimage;
+
+ int is_bootable;/* Default to 0 */
+ int64_t boot_catalog_sector;
+ boot_volume_descriptor *boot_descriptor;
+ char * boot_image_directory;
+
+ TAILQ_HEAD(boot_image_list,cd9660_boot_image) boot_images;
+ int image_serialno;
+ LIST_HEAD(boot_catalog_entries,boot_catalog_entry) boot_entries;
+
+} iso9660_disk;
+
+/******** GLOBAL VARIABLES ***********/
+extern iso9660_disk diskStructure;
+
+/************ FUNCTIONS **************/
+int cd9660_valid_a_chars(const char *);
+int cd9660_valid_d_chars(const char *);
+void cd9660_uppercase_characters(char *, int);
+
+/* ISO Data Types */
+void cd9660_721(uint16_t, unsigned char *);
+void cd9660_731(uint32_t, unsigned char *);
+void cd9660_722(uint16_t, unsigned char *);
+void cd9660_732(uint32_t, unsigned char *);
+void cd9660_bothendian_dword(uint32_t dw, unsigned char *);
+void cd9660_bothendian_word(uint16_t dw, unsigned char *);
+void cd9660_set_date(char *, time_t);
+void cd9660_time_8426(unsigned char *, time_t);
+void cd9660_time_915(unsigned char *, time_t);
+
+/*** Boot Functions ***/
+int cd9660_write_generic_bootimage(FILE *);
+int cd9660_add_generic_bootimage(const char *);
+int cd9660_write_boot(FILE *);
+int cd9660_add_boot_disk(const char *);
+int cd9660_eltorito_add_boot_option(const char *, const char *);
+int cd9660_setup_boot(int);
+int cd9660_setup_boot_volume_descriptor(volume_descriptor *);
+
+
+/*** Write Functions ***/
+int cd9660_write_image(const char *image);
+int cd9660_copy_file(FILE *, off_t, const char *);
+
+void cd9660_compute_full_filename(cd9660node *, char *, int);
+int cd9660_compute_record_size(cd9660node *);
+
+/* Debugging functions */
+void debug_print_tree(cd9660node *,int);
+void debug_print_path_tree(cd9660node *);
+void debug_print_volume_descriptor_information(void);
+void debug_dump_to_xml_ptentry(path_table_entry *,int, int);
+void debug_dump_to_xml_path_table(FILE *, off_t, int, int);
+void debug_dump_to_xml(FILE *);
+int debug_get_encoded_number(unsigned char *, int);
+void debug_dump_integer(const char *, char *,int);
+void debug_dump_string(const char *,unsigned char *,int);
+void debug_dump_directory_record_9_1(unsigned char *);
+void debug_dump_to_xml_volume_descriptor(unsigned char *,int);
+
+void cd9660_pad_string_spaces(char *, int);
+
+#endif
diff --git a/usr.sbin/makefs/cd9660/Makefile.inc b/usr.sbin/makefs/cd9660/Makefile.inc
new file mode 100644
index 0000000..1455fcd
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/Makefile.inc
@@ -0,0 +1,9 @@
+# $FreeBSD$
+#
+
+.PATH: ${.CURDIR}/cd9660 ${.CURDIR}/../../sys/fs/cd9660/
+
+CFLAGS+=-I${.CURDIR}/../../sys/fs/cd9660/
+
+SRCS+= cd9660_strings.c cd9660_debug.c cd9660_eltorito.c \
+ cd9660_write.c cd9660_conversion.c iso9660_rrip.c cd9660_archimedes.c
diff --git a/usr.sbin/makefs/cd9660/cd9660_archimedes.c b/usr.sbin/makefs/cd9660/cd9660_archimedes.c
new file mode 100644
index 0000000..d18a0f7
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_archimedes.c
@@ -0,0 +1,126 @@
+/* $NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2009 Ben Harris
+ * 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.
+ */
+/*
+ * cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
+ *
+ * RISC OS CDFS looks for a special block at the end of the System Use
+ * Field for each file. If present, this contains the RISC OS load
+ * and exec address (used to hold the file timestamp and type), the
+ * file attributes, and a flag indicating whether the first character
+ * of the filename should be replaced with '!' (since many special
+ * RISC OS filenames do).
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "makefs.h"
+#include "cd9660.h"
+#include "cd9660_archimedes.h"
+
+/*
+ * Convert a Unix time_t (non-leap seconds since 1970-01-01) to a RISC
+ * OS time (non-leap(?) centiseconds since 1900-01-01(?)).
+ */
+
+static u_int64_t
+riscos_date(time_t unixtime)
+{
+ u_int64_t base;
+
+ base = 31536000ULL * 70 + 86400 * 17;
+ return (((u_int64_t)unixtime) + base)*100;
+}
+
+/*
+ * Add "ARCHIMEDES" metadata to a node if that seems appropriate.
+ *
+ * We touch regular files with names matching /,[0-9a-f]{3}$/ and
+ * directories matching /^!/.
+ */
+static void
+archimedes_convert_node(cd9660node *node)
+{
+ struct ISO_ARCHIMEDES *arc;
+ size_t len;
+ int type = -1;
+ uint64_t stamp;
+
+ if (node->su_tail_data != NULL)
+ /* Something else already has the tail. */
+ return;
+
+ len = strlen(node->node->name);
+ if (len < 1) return;
+
+ if (len >= 4 && node->node->name[len-4] == ',')
+ /* XXX should support ,xxx and ,lxa */
+ type = strtoul(node->node->name + len - 3, NULL, 16);
+ if (type == -1 && node->node->name[0] != '!')
+ return;
+ if (type == -1) type = 0;
+
+ assert(sizeof(struct ISO_ARCHIMEDES) == 32);
+ if ((arc = calloc(1, sizeof(struct ISO_ARCHIMEDES))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("archimedes_convert_node");
+ exit(1);
+ }
+
+ stamp = riscos_date(node->node->inode->st.st_mtime);
+
+ memcpy(arc->magic, "ARCHIMEDES", 10);
+ cd9660_731(0xfff00000 | (type << 8) | (stamp >> 32), arc->loadaddr);
+ cd9660_731(stamp & 0x00ffffffffULL, arc->execaddr);
+ arc->ro_attr = RO_ACCESS_UR | RO_ACCESS_OR;
+ arc->cdfs_attr = node->node->name[0] == '!' ? CDFS_PLING : 0;
+ node->su_tail_data = (void *)arc;
+ node->su_tail_size = sizeof(*arc);
+}
+
+/*
+ * Add "ARCHIMEDES" metadata to an entire tree recursively.
+ */
+void
+archimedes_convert_tree(cd9660node *node)
+{
+ cd9660node *cn;
+
+ assert(node != NULL);
+
+ archimedes_convert_node(node);
+
+ /* Recurse on children. */
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
+ archimedes_convert_tree(cn);
+}
diff --git a/usr.sbin/makefs/cd9660/cd9660_archimedes.h b/usr.sbin/makefs/cd9660/cd9660_archimedes.h
new file mode 100644
index 0000000..2717bf4
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_archimedes.h
@@ -0,0 +1,50 @@
+/* $NetBSD: cd9660_archimedes.h,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2009 Ben Harris
+ * 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.
+ */
+/*
+ * cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
+ *
+ * $FreeBSD$
+ */
+
+struct ISO_ARCHIMEDES {
+ char magic[10]; /* "ARCHIMEDES" */
+ unsigned char loadaddr[4]; /* Load address, little-endian */
+ unsigned char execaddr[4]; /* Exec address, little-endian */
+ unsigned char ro_attr; /* RISC OS attributes */
+#define RO_ACCESS_UR 0x01 /* Owner read */
+#define RO_ACCESS_UW 0x02 /* Owner write */
+#define RO_ACCESS_L 0x04 /* Locked */
+#define RO_ACCESS_OR 0x10 /* Public read */
+#define RO_ACCESS_OW 0x20 /* Public write */
+ unsigned char cdfs_attr; /* Extra attributes for CDFS */
+#define CDFS_PLING 0x01 /* Filename begins with '!' */
+ char reserved[12];
+};
+
+extern void archimedes_convert_tree(cd9660node *);
diff --git a/usr.sbin/makefs/cd9660/cd9660_conversion.c b/usr.sbin/makefs/cd9660/cd9660_conversion.c
new file mode 100644
index 0000000..e815028
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_conversion.c
@@ -0,0 +1,202 @@
+/* $NetBSD: cd9660_conversion.c,v 1.4 2007/03/14 14:11:17 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+#include "cd9660.h"
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/endian.h>
+
+static char cd9660_compute_gm_offset(time_t);
+
+#if 0
+static inline int
+cd9660_pad_even(length)
+int length;
+{
+ return length + (length & 0x01);
+}
+#endif
+
+/*
+* These can probably be implemented using a macro
+*/
+
+/* Little endian */
+void
+cd9660_721(uint16_t w, unsigned char *twochar)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+ w = bswap16(w);
+#endif
+ memcpy(twochar,&w,2);
+}
+
+void
+cd9660_731(uint32_t w, unsigned char *fourchar)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+ w = bswap32(w);
+#endif
+ memcpy(fourchar,&w,4);
+}
+
+/* Big endian */
+void
+cd9660_722(uint16_t w, unsigned char *twochar)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ w = bswap16(w);
+#endif
+ memcpy(twochar,&w,2);
+}
+
+void
+cd9660_732(uint32_t w, unsigned char *fourchar)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ w = bswap32(w);
+#endif
+ memcpy(fourchar,&w,4);
+}
+
+/**
+* Convert a dword into a double endian string of eight characters
+* @param int The double word to convert
+* @param char* The string to write the both endian double word to - It is assumed this is allocated and at least
+* eight characters long
+*/
+void
+cd9660_bothendian_dword(uint32_t dw, unsigned char *eightchar)
+{
+ uint32_t le, be;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ le = dw;
+ be = bswap32(dw);
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ be = dw;
+ le = bswap32(dw);
+#endif
+ memcpy(eightchar, &le, 4);
+ memcpy((eightchar+4), &be, 4);
+}
+
+/**
+* Convert a word into a double endian string of four characters
+* @param int The word to convert
+* @param char* The string to write the both endian word to - It is assumed this is allocated and at least
+* four characters long
+*/
+void
+cd9660_bothendian_word(uint16_t dw, unsigned char *fourchar)
+{
+ uint16_t le, be;
+#if BYTE_ORDER == LITTLE_ENDIAN
+ le = dw;
+ be = bswap16(dw);
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+ be = dw;
+ le = bswap16(dw);
+#endif
+ memcpy(fourchar, &le, 2);
+ memcpy((fourchar+2), &be, 2);
+}
+
+void
+cd9660_pad_string_spaces(char *str, int len)
+{
+ int i;
+
+ for (i = 0; i < len; i ++) {
+ if (str[i] == '\0')
+ str[i] = 0x20;
+ }
+}
+
+static char
+cd9660_compute_gm_offset(time_t tim)
+{
+ struct tm t, gm;
+
+ (void)localtime_r(&tim, &t);
+ (void)gmtime_r(&tim, &gm);
+ gm.tm_year -= t.tm_year;
+ gm.tm_yday -= t.tm_yday;
+ gm.tm_hour -= t.tm_hour;
+ gm.tm_min -= t.tm_min;
+ if (gm.tm_year < 0)
+ gm.tm_yday = -1;
+ else if (gm.tm_year > 0)
+ gm.tm_yday = 1;
+
+ return (char)(-(gm.tm_min + 60* (24 * gm.tm_yday + gm.tm_hour)) / 15);
+}
+
+/* Long dates: 17 characters */
+void
+cd9660_time_8426(unsigned char *buf, time_t tim)
+{
+ struct tm t;
+ char temp[18];
+
+ (void)localtime_r(&tim, &t);
+ (void)snprintf(temp, sizeof(temp), "%04i%02i%02i%02i%02i%02i%02i",
+ 1900+(int)t.tm_year,
+ (int)t.tm_mon+1,
+ (int)t.tm_mday,
+ (int)t.tm_hour,
+ (int)t.tm_min,
+ (int)t.tm_sec,
+ 0);
+ (void)memcpy(buf, temp, 16);
+ buf[16] = cd9660_compute_gm_offset(tim);
+}
+
+/* Short dates: 7 characters */
+void
+cd9660_time_915(unsigned char *buf, time_t tim)
+{
+ struct tm t;
+
+ (void)localtime_r(&tim, &t);
+ buf[0] = t.tm_year;
+ buf[1] = t.tm_mon+1;
+ buf[2] = t.tm_mday;
+ buf[3] = t.tm_hour;
+ buf[4] = t.tm_min;
+ buf[5] = t.tm_sec;
+ buf[6] = cd9660_compute_gm_offset(tim);
+}
diff --git a/usr.sbin/makefs/cd9660/cd9660_debug.c b/usr.sbin/makefs/cd9660/cd9660_debug.c
new file mode 100644
index 0000000..d94ccbe
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_debug.c
@@ -0,0 +1,488 @@
+/* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+
+#include <sys/mount.h>
+
+#include "makefs.h"
+#include "cd9660.h"
+#include "iso9660_rrip.h"
+
+static void debug_print_susp_attrs(cd9660node *, int);
+static void debug_dump_to_xml_padded_hex_output(const char *, unsigned char *,
+ int);
+
+static inline void
+print_n_tabs(int n)
+{
+ int i;
+
+ for (i = 1; i <= n; i ++)
+ printf("\t");
+}
+
+#if 0
+void
+debug_print_rrip_info(n)
+cd9660node *n;
+{
+ struct ISO_SUSP_ATTRIBUTES *t;
+ TAILQ_FOREACH(t, &node->head, rr_ll) {
+
+ }
+}
+#endif
+
+static void
+debug_print_susp_attrs(cd9660node *n, int indent)
+{
+ struct ISO_SUSP_ATTRIBUTES *t;
+
+ TAILQ_FOREACH(t, &n->head, rr_ll) {
+ print_n_tabs(indent);
+ printf("-");
+ printf("%c%c: L:%i",t->attr.su_entry.SP.h.type[0],
+ t->attr.su_entry.SP.h.type[1],
+ (int)t->attr.su_entry.SP.h.length[0]);
+ printf("\n");
+ }
+}
+
+void
+debug_print_tree(cd9660node *node, int level)
+{
+#if !HAVE_NBTOOL_CONFIG_H
+ cd9660node *cn;
+
+ print_n_tabs(level);
+ if (node->type & CD9660_TYPE_DOT) {
+ printf(". (%i)\n",
+ isonum_733(node->isoDirRecord->extent));
+ } else if (node->type & CD9660_TYPE_DOTDOT) {
+ printf("..(%i)\n",
+ isonum_733(node->isoDirRecord->extent));
+ } else if (node->isoDirRecord->name[0]=='\0') {
+ printf("(ROOT) (%" PRIu32 " to %" PRId64 ")\n",
+ node->fileDataSector,
+ node->fileDataSector +
+ node->fileSectorsUsed - 1);
+ } else {
+ printf("%s (%s) (%" PRIu32 " to %" PRId64 ")\n",
+ node->isoDirRecord->name,
+ (node->isoDirRecord->flags[0]
+ & ISO_FLAG_DIRECTORY) ? "DIR" : "FILE",
+ node->fileDataSector,
+ (node->fileSectorsUsed == 0) ?
+ node->fileDataSector :
+ node->fileDataSector
+ + node->fileSectorsUsed - 1);
+ }
+ if (diskStructure.rock_ridge_enabled)
+ debug_print_susp_attrs(node, level + 1);
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
+ debug_print_tree(cn, level + 1);
+#else
+ printf("Sorry, debugging is not supported in host-tools mode.\n");
+#endif
+}
+
+void
+debug_print_path_tree(cd9660node *n)
+{
+ cd9660node *iterator = n;
+
+ /* Only display this message when called with the root node */
+ if (n->parent == NULL)
+ printf("debug_print_path_table: Dumping path table contents\n");
+
+ while (iterator != NULL) {
+ if (iterator->isoDirRecord->name[0] == '\0')
+ printf("0) (ROOT)\n");
+ else
+ printf("%i) %s\n", iterator->level,
+ iterator->isoDirRecord->name);
+
+ iterator = iterator->ptnext;
+ }
+}
+
+void
+debug_print_volume_descriptor_information(void)
+{
+ volume_descriptor *tmp = diskStructure.firstVolumeDescriptor;
+ char temp[CD9660_SECTOR_SIZE];
+
+ printf("==Listing Volume Descriptors==\n");
+
+ while (tmp != NULL) {
+ memset(temp, 0, CD9660_SECTOR_SIZE);
+ memcpy(temp, tmp->volumeDescriptorData + 1, 5);
+ printf("Volume descriptor in sector %" PRId64
+ ": type %i, ID %s\n",
+ tmp->sector, tmp->volumeDescriptorData[0], temp);
+ switch(tmp->volumeDescriptorData[0]) {
+ case 0:/*boot record*/
+ break;
+
+ case 1: /* PVD */
+ break;
+
+ case 2: /* SVD */
+ break;
+
+ case 3: /* Volume Partition Descriptor */
+ break;
+
+ case 255: /* terminator */
+ break;
+ }
+ tmp = tmp->next;
+ }
+
+ printf("==Done Listing Volume Descriptors==\n");
+}
+
+void
+debug_dump_to_xml_ptentry(path_table_entry *pttemp, int num, int mode)
+{
+ printf("<ptentry num=\"%i\">\n" ,num);
+ printf("<length>%i</length>\n", pttemp->length[0]);
+ printf("<extended_attribute_length>%i</extended_attribute_length>\n",
+ pttemp->extended_attribute_length[0]);
+ printf("<parent_number>%i</parent_number>\n",
+ debug_get_encoded_number(pttemp->parent_number,mode));
+ debug_dump_to_xml_padded_hex_output("name",
+ pttemp->name, pttemp->length[0]);
+ printf("</ptentry>\n");
+}
+
+void
+debug_dump_to_xml_path_table(FILE *fd, off_t sector, int size, int mode)
+{
+ path_table_entry pttemp;
+ int t = 0;
+ int n = 0;
+
+ if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ while (t < size) {
+ /* Read fixed data first */
+ fread(&pttemp, 1, 8, fd);
+ t += 8;
+ /* Read variable */
+ fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0], fd);
+ t += pttemp.length[0];
+ debug_dump_to_xml_ptentry(&pttemp, n, mode);
+ n++;
+ }
+
+}
+
+/*
+ * XML Debug output functions
+ * Dump hierarchy of CD, as well as volume info, to XML
+ * Can be used later to diff against a standard,
+ * or just provide easy to read detailed debug output
+ */
+void
+debug_dump_to_xml(FILE *fd)
+{
+ unsigned char buf[CD9660_SECTOR_SIZE];
+ off_t sector;
+ int t, t2;
+ struct iso_primary_descriptor primaryVD;
+ struct _boot_volume_descriptor bootVD;
+
+ printf("<cd9660dump>\n");
+
+ /* Display Volume Descriptors */
+ sector = 16;
+ do {
+ if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
+ err(1, "fseeko");
+ fread(buf, 1, CD9660_SECTOR_SIZE, fd);
+ t = (int)((unsigned char)buf[0]);
+ switch (t) {
+ case 0:
+ memcpy(&bootVD, buf, CD9660_SECTOR_SIZE);
+ break;
+ case 1:
+ memcpy(&primaryVD, buf, CD9660_SECTOR_SIZE);
+ break;
+ }
+ debug_dump_to_xml_volume_descriptor(buf, sector);
+ sector++;
+ } while (t != 255);
+
+ t = debug_get_encoded_number((u_char *)primaryVD.type_l_path_table,
+ 731);
+ t2 = debug_get_encoded_number((u_char *)primaryVD.path_table_size, 733);
+ printf("Path table 1 located at sector %i and is %i bytes long\n",
+ t,t2);
+ debug_dump_to_xml_path_table(fd, t, t2, 721);
+
+ t = debug_get_encoded_number((u_char *)primaryVD.type_m_path_table,
+ 731);
+ debug_dump_to_xml_path_table(fd, t, t2, 722);
+
+ printf("</cd9660dump>\n");
+}
+
+static void
+debug_dump_to_xml_padded_hex_output(const char *element, unsigned char *buf,
+ int len)
+{
+ int i;
+ int t;
+
+ printf("<%s>",element);
+ for (i = 0; i < len; i++) {
+ t = (unsigned char)buf[i];
+ if (t >= 32 && t < 127)
+ printf("%c",t);
+ }
+ printf("</%s>\n",element);
+
+ printf("<%s:hex>",element);
+ for (i = 0; i < len; i++) {
+ t = (unsigned char)buf[i];
+ printf(" %x",t);
+ }
+ printf("</%s:hex>\n",element);
+}
+
+int
+debug_get_encoded_number(unsigned char* buf, int mode)
+{
+#if !HAVE_NBTOOL_CONFIG_H
+ switch (mode) {
+ /* 711: Single bite */
+ case 711:
+ return isonum_711(buf);
+
+ /* 712: Single signed byte */
+ case 712:
+ return isonum_712((signed char *)buf);
+
+ /* 721: 16 bit LE */
+ case 721:
+ return isonum_721(buf);
+
+ /* 731: 32 bit LE */
+ case 731:
+ return isonum_731(buf);
+
+ /* 722: 16 bit BE */
+ case 722:
+ return isonum_722(buf);
+
+ /* 732: 32 bit BE */
+ case 732:
+ return isonum_732(buf);
+
+ /* 723: 16 bit bothE */
+ case 723:
+ return isonum_723(buf);
+
+ /* 733: 32 bit bothE */
+ case 733:
+ return isonum_733(buf);
+ }
+#endif
+ return 0;
+}
+
+void
+debug_dump_integer(const char *element, char* buf, int mode)
+{
+ printf("<%s>%i</%s>\n", element,
+ debug_get_encoded_number((unsigned char *)buf, mode), element);
+}
+
+void
+debug_dump_string(const char *element __unused, unsigned char *buf __unused, int len __unused)
+{
+
+}
+
+void
+debug_dump_directory_record_9_1(unsigned char* buf)
+{
+ printf("<directoryrecord>\n");
+ debug_dump_integer("length",
+ ((struct iso_directory_record*) buf)->length, 711);
+ debug_dump_integer("ext_attr_length",
+ ((struct iso_directory_record*) buf)->ext_attr_length,711);
+ debug_dump_integer("extent",
+ (char *)((struct iso_directory_record*) buf)->extent, 733);
+ debug_dump_integer("size",
+ (char *)((struct iso_directory_record*) buf)->size, 733);
+ debug_dump_integer("flags",
+ ((struct iso_directory_record*) buf)->flags, 711);
+ debug_dump_integer("file_unit_size",
+ ((struct iso_directory_record*) buf)->file_unit_size,711);
+ debug_dump_integer("interleave",
+ ((struct iso_directory_record*) buf)->interleave, 711);
+ debug_dump_integer("volume_sequence_number",
+ ((struct iso_directory_record*) buf)->volume_sequence_number,
+ 723);
+ debug_dump_integer("name_len",
+ ((struct iso_directory_record*) buf)->name_len, 711);
+ debug_dump_to_xml_padded_hex_output("name",
+ (u_char *)((struct iso_directory_record*) buf)->name,
+ debug_get_encoded_number((u_char *)
+ ((struct iso_directory_record*) buf)->length, 711));
+ printf("</directoryrecord>\n");
+}
+
+
+void
+debug_dump_to_xml_volume_descriptor(unsigned char* buf, int sector)
+{
+ printf("<volumedescriptor sector=\"%i\">\n", sector);
+ printf("<vdtype>");
+ switch(buf[0]) {
+ case 0:
+ printf("boot");
+ break;
+
+ case 1:
+ printf("primary");
+ break;
+
+ case 2:
+ printf("supplementary");
+ break;
+
+ case 3:
+ printf("volume partition descriptor");
+ break;
+
+ case 255:
+ printf("terminator");
+ break;
+ }
+
+ printf("</vdtype>\n");
+ switch(buf[0]) {
+ case 1:
+ debug_dump_integer("type",
+ ((struct iso_primary_descriptor*)buf)->type, 711);
+ debug_dump_to_xml_padded_hex_output("id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->id,
+ ISODCL ( 2, 6));
+ debug_dump_integer("version",
+ ((struct iso_primary_descriptor*)buf)->version,
+ 711);
+ debug_dump_to_xml_padded_hex_output("system_id",
+ (u_char *)((struct iso_primary_descriptor*)buf)->system_id,
+ ISODCL(9,40));
+ debug_dump_to_xml_padded_hex_output("volume_id",
+ (u_char *)((struct iso_primary_descriptor*)buf)->volume_id,
+ ISODCL(41,72));
+ debug_dump_integer("volume_space_size",
+ ((struct iso_primary_descriptor*)buf)->volume_space_size,
+ 733);
+ debug_dump_integer("volume_set_size",
+ ((struct iso_primary_descriptor*)buf)->volume_set_size,
+ 733);
+ debug_dump_integer("volume_sequence_number",
+ ((struct iso_primary_descriptor*)buf)->volume_sequence_number,
+ 723);
+ debug_dump_integer("logical_block_size",
+ ((struct iso_primary_descriptor*)buf)->logical_block_size,
+ 723);
+ debug_dump_integer("path_table_size",
+ ((struct iso_primary_descriptor*)buf)->path_table_size,
+ 733);
+ debug_dump_integer("type_l_path_table",
+ ((struct iso_primary_descriptor*)buf)->type_l_path_table,
+ 731);
+ debug_dump_integer("opt_type_l_path_table",
+ ((struct iso_primary_descriptor*)buf)->opt_type_l_path_table,
+ 731);
+ debug_dump_integer("type_m_path_table",
+ ((struct iso_primary_descriptor*)buf)->type_m_path_table,
+ 732);
+ debug_dump_integer("opt_type_m_path_table",
+ ((struct iso_primary_descriptor*)buf)->opt_type_m_path_table,732);
+ debug_dump_directory_record_9_1(
+ (u_char *)((struct iso_primary_descriptor*)buf)->root_directory_record);
+ debug_dump_to_xml_padded_hex_output("volume_set_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->volume_set_id,
+ ISODCL (191, 318));
+ debug_dump_to_xml_padded_hex_output("publisher_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->publisher_id,
+ ISODCL (319, 446));
+ debug_dump_to_xml_padded_hex_output("preparer_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->preparer_id,
+ ISODCL (447, 574));
+ debug_dump_to_xml_padded_hex_output("application_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->application_id,
+ ISODCL (575, 702));
+ debug_dump_to_xml_padded_hex_output("copyright_file_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->copyright_file_id,
+ ISODCL (703, 739));
+ debug_dump_to_xml_padded_hex_output("abstract_file_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->abstract_file_id,
+ ISODCL (740, 776));
+ debug_dump_to_xml_padded_hex_output("bibliographic_file_id",
+ (u_char *)((struct iso_primary_descriptor*) buf)->bibliographic_file_id,
+ ISODCL (777, 813));
+
+ debug_dump_to_xml_padded_hex_output("creation_date",
+ (u_char *)((struct iso_primary_descriptor*) buf)->creation_date,
+ ISODCL (814, 830));
+ debug_dump_to_xml_padded_hex_output("modification_date",
+ (u_char *)((struct iso_primary_descriptor*) buf)->modification_date,
+ ISODCL (831, 847));
+ debug_dump_to_xml_padded_hex_output("expiration_date",
+ (u_char *)((struct iso_primary_descriptor*) buf)->expiration_date,
+ ISODCL (848, 864));
+ debug_dump_to_xml_padded_hex_output("effective_date",
+ (u_char *)((struct iso_primary_descriptor*) buf)->effective_date,
+ ISODCL (865, 881));
+
+ debug_dump_to_xml_padded_hex_output("file_structure_version",
+ (u_char *)((struct iso_primary_descriptor*) buf)->file_structure_version,
+ ISODCL(882,882));
+ break;
+ }
+ printf("</volumedescriptor>\n");
+}
+
diff --git a/usr.sbin/makefs/cd9660/cd9660_eltorito.c b/usr.sbin/makefs/cd9660/cd9660_eltorito.c
new file mode 100644
index 0000000..055451d
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_eltorito.c
@@ -0,0 +1,539 @@
+/* $NetBSD: cd9660_eltorito.c,v 1.14 2010/10/27 18:51:35 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+#include "cd9660.h"
+#include "cd9660_eltorito.h"
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifdef DEBUG
+#define ELTORITO_DPRINTF(__x) printf __x
+#else
+#define ELTORITO_DPRINTF(__x)
+#endif
+
+static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void);
+static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char);
+static struct boot_catalog_entry *cd9660_boot_setup_default_entry(
+ struct cd9660_boot_image *);
+static struct boot_catalog_entry *cd9660_boot_setup_section_head(char);
+static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char);
+#if 0
+static u_char cd9660_boot_get_system_type(struct cd9660_boot_image *);
+#endif
+
+int
+cd9660_add_boot_disk(const char *boot_info)
+{
+ struct stat stbuf;
+ const char *mode_msg;
+ char *temp;
+ char *sysname;
+ char *filename;
+ struct cd9660_boot_image *new_image, *tmp_image;
+
+ assert(boot_info != NULL);
+
+ if (*boot_info == '\0') {
+ warnx("Error: Boot disk information must be in the "
+ "format 'system;filename'");
+ return 0;
+ }
+
+ /* First decode the boot information */
+ if ((temp = strdup(boot_info)) == NULL) {
+ warn("%s: strdup", __func__);
+ return 0;
+ }
+
+ sysname = temp;
+ filename = strchr(sysname, ';');
+ if (filename == NULL) {
+ warnx("supply boot disk information in the format "
+ "'system;filename'");
+ free(temp);
+ return 0;
+ }
+
+ *filename++ = '\0';
+
+ if (diskStructure.verbose_level > 0) {
+ printf("Found bootdisk with system %s, and filename %s\n",
+ sysname, filename);
+ }
+ if ((new_image = malloc(sizeof(*new_image))) == NULL) {
+ warn("%s: malloc", __func__);
+ free(temp);
+ return 0;
+ }
+ (void)memset(new_image, 0, sizeof(*new_image));
+ new_image->loadSegment = 0; /* default for now */
+
+ /* Decode System */
+ if (strcmp(sysname, "i386") == 0)
+ new_image->system = ET_SYS_X86;
+ else if (strcmp(sysname, "powerpc") == 0)
+ new_image->system = ET_SYS_PPC;
+ else if (strcmp(sysname, "macppc") == 0 ||
+ strcmp(sysname, "mac68k") == 0)
+ new_image->system = ET_SYS_MAC;
+ else {
+ warnx("boot disk system must be "
+ "i386, powerpc, macppc, or mac68k");
+ free(temp);
+ free(new_image);
+ return 0;
+ }
+
+
+ if ((new_image->filename = strdup(filename)) == NULL) {
+ warn("%s: strdup", __func__);
+ free(temp);
+ free(new_image);
+ return 0;
+ }
+
+ free(temp);
+
+ /* Get information about the file */
+ if (lstat(new_image->filename, &stbuf) == -1)
+ err(EXIT_FAILURE, "%s: lstat(\"%s\")", __func__,
+ new_image->filename);
+
+ switch (stbuf.st_size) {
+ case 1440 * 1024:
+ new_image->targetMode = ET_MEDIA_144FDD;
+ mode_msg = "Assigned boot image to 1.44 emulation mode";
+ break;
+ case 1200 * 1024:
+ new_image->targetMode = ET_MEDIA_12FDD;
+ mode_msg = "Assigned boot image to 1.2 emulation mode";
+ break;
+ case 2880 * 1024:
+ new_image->targetMode = ET_MEDIA_288FDD;
+ mode_msg = "Assigned boot image to 2.88 emulation mode";
+ break;
+ default:
+ new_image->targetMode = ET_MEDIA_NOEM;
+ mode_msg = "Assigned boot image to no emulation mode";
+ break;
+ }
+
+ if (diskStructure.verbose_level > 0)
+ printf("%s\n", mode_msg);
+
+ new_image->size = stbuf.st_size;
+ new_image->num_sectors =
+ howmany(new_image->size, diskStructure.sectorSize) *
+ howmany(diskStructure.sectorSize, 512);
+ if (diskStructure.verbose_level > 0) {
+ printf("New image has size %d, uses %d 512-byte sectors\n",
+ new_image->size, new_image->num_sectors);
+ }
+ new_image->sector = -1;
+ /* Bootable by default */
+ new_image->bootable = ET_BOOTABLE;
+ /* Add boot disk */
+
+ /* Group images for the same platform together. */
+ TAILQ_FOREACH(tmp_image, &diskStructure.boot_images, image_list) {
+ if (tmp_image->system != new_image->system)
+ break;
+ }
+
+ if (tmp_image == NULL) {
+ TAILQ_INSERT_HEAD(&diskStructure.boot_images, new_image,
+ image_list);
+ } else
+ TAILQ_INSERT_BEFORE(tmp_image, new_image, image_list);
+
+ new_image->serialno = diskStructure.image_serialno++;
+
+ /* TODO : Need to do anything about the boot image in the tree? */
+ diskStructure.is_bootable = 1;
+
+ return 1;
+}
+
+int
+cd9660_eltorito_add_boot_option(const char *option_string, const char *value)
+{
+ char *eptr;
+ struct cd9660_boot_image *image;
+
+ assert(option_string != NULL);
+
+ /* Find the last image added */
+ TAILQ_FOREACH(image, &diskStructure.boot_images, image_list) {
+ if (image->serialno + 1 == diskStructure.image_serialno)
+ break;
+ }
+ if (image == NULL)
+ errx(EXIT_FAILURE, "Attempted to add boot option, "
+ "but no boot images have been specified");
+
+ if (strcmp(option_string, "no-emul-boot") == 0) {
+ image->targetMode = ET_MEDIA_NOEM;
+ } else if (strcmp(option_string, "no-boot") == 0) {
+ image->bootable = ET_NOT_BOOTABLE;
+ } else if (strcmp(option_string, "hard-disk-boot") == 0) {
+ image->targetMode = ET_MEDIA_HDD;
+ } else if (strcmp(option_string, "boot-load-segment") == 0) {
+ image->loadSegment = strtoul(value, &eptr, 16);
+ if (eptr == value || *eptr != '\0' || errno != ERANGE) {
+ warn("%s: strtoul", __func__);
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+ return 1;
+}
+
+static struct boot_catalog_entry *
+cd9660_init_boot_catalog_entry(void)
+{
+ struct boot_catalog_entry *temp;
+
+ if ((temp = malloc(sizeof(*temp))) == NULL)
+ return NULL;
+
+ return memset(temp, 0, sizeof(*temp));
+}
+
+static struct boot_catalog_entry *
+cd9660_boot_setup_validation_entry(char sys)
+{
+ struct boot_catalog_entry *entry;
+ boot_catalog_validation_entry *ve;
+ int16_t checksum;
+ unsigned char *csptr;
+ int i;
+ entry = cd9660_init_boot_catalog_entry();
+
+ if (entry == NULL) {
+ warnx("Error: memory allocation failed in "
+ "cd9660_boot_setup_validation_entry");
+ return 0;
+ }
+ ve = &entry->entry_data.VE;
+
+ ve->header_id[0] = 1;
+ ve->platform_id[0] = sys;
+ ve->key[0] = 0x55;
+ ve->key[1] = 0xAA;
+
+ /* Calculate checksum */
+ checksum = 0;
+ cd9660_721(0, ve->checksum);
+ csptr = (unsigned char*)ve;
+ for (i = 0; i < sizeof(*ve); i += 2) {
+ checksum += (int16_t)csptr[i];
+ checksum += 256 * (int16_t)csptr[i + 1];
+ }
+ checksum = -checksum;
+ cd9660_721(checksum, ve->checksum);
+
+ ELTORITO_DPRINTF(("%s: header_id %d, platform_id %d, key[0] %d, key[1] %d, "
+ "checksum %04x\n", __func__, ve->header_id[0], ve->platform_id[0],
+ ve->key[0], ve->key[1], checksum));
+ return entry;
+}
+
+static struct boot_catalog_entry *
+cd9660_boot_setup_default_entry(struct cd9660_boot_image *disk)
+{
+ struct boot_catalog_entry *default_entry;
+ boot_catalog_initial_entry *ie;
+
+ default_entry = cd9660_init_boot_catalog_entry();
+ if (default_entry == NULL)
+ return NULL;
+
+ ie = &default_entry->entry_data.IE;
+
+ ie->boot_indicator[0] = disk->bootable;
+ ie->media_type[0] = disk->targetMode;
+ cd9660_721(disk->loadSegment, ie->load_segment);
+ ie->system_type[0] = disk->system;
+ cd9660_721(disk->num_sectors, ie->sector_count);
+ cd9660_731(disk->sector, ie->load_rba);
+
+ ELTORITO_DPRINTF(("%s: boot indicator %d, media type %d, "
+ "load segment %04x, system type %d, sector count %d, "
+ "load rba %d\n", __func__, ie->boot_indicator[0],
+ ie->media_type[0], disk->loadSegment, ie->system_type[0],
+ disk->num_sectors, disk->sector));
+ return default_entry;
+}
+
+static struct boot_catalog_entry *
+cd9660_boot_setup_section_head(char platform)
+{
+ struct boot_catalog_entry *entry;
+ boot_catalog_section_header *sh;
+
+ entry = cd9660_init_boot_catalog_entry();
+ if (entry == NULL)
+ return NULL;
+
+ sh = &entry->entry_data.SH;
+ /* More by default. The last one will manually be set to 0x91 */
+ sh->header_indicator[0] = ET_SECTION_HEADER_MORE;
+ sh->platform_id[0] = platform;
+ sh->num_section_entries[0] = 0;
+ return entry;
+}
+
+static struct boot_catalog_entry *
+cd9660_boot_setup_section_entry(struct cd9660_boot_image *disk)
+{
+ struct boot_catalog_entry *entry;
+ boot_catalog_section_entry *se;
+ if ((entry = cd9660_init_boot_catalog_entry()) == NULL)
+ return NULL;
+
+ se = &entry->entry_data.SE;
+
+ se->boot_indicator[0] = ET_BOOTABLE;
+ se->media_type[0] = disk->targetMode;
+ cd9660_721(disk->loadSegment, se->load_segment);
+ cd9660_721(disk->num_sectors, se->sector_count);
+ cd9660_731(disk->sector, se->load_rba);
+ return entry;
+}
+
+#if 0
+static u_char
+cd9660_boot_get_system_type(struct cd9660_boot_image *disk)
+{
+ /*
+ For hard drive booting, we need to examine the MBR to figure
+ out what the partition type is
+ */
+ return 0;
+}
+#endif
+
+/*
+ * Set up the BVD, Boot catalog, and the boot entries, but do no writing
+ */
+int
+cd9660_setup_boot(int first_sector)
+{
+ int sector;
+ int used_sectors;
+ int num_entries = 0;
+ int catalog_sectors;
+ struct boot_catalog_entry *x86_head, *mac_head, *ppc_head,
+ *valid_entry, *default_entry, *temp, *head, **headp, *next;
+ struct cd9660_boot_image *tmp_disk;
+
+ headp = NULL;
+ x86_head = mac_head = ppc_head = NULL;
+
+ /* If there are no boot disks, don't bother building boot information */
+ if (TAILQ_EMPTY(&diskStructure.boot_images))
+ return 0;
+
+ /* Point to catalog: For now assume it consumes one sector */
+ ELTORITO_DPRINTF(("Boot catalog will go in sector %d\n", first_sector));
+ diskStructure.boot_catalog_sector = first_sector;
+ cd9660_bothendian_dword(first_sector,
+ diskStructure.boot_descriptor->boot_catalog_pointer);
+
+ /* Step 1: Generate boot catalog */
+ /* Step 1a: Validation entry */
+ valid_entry = cd9660_boot_setup_validation_entry(ET_SYS_X86);
+ if (valid_entry == NULL)
+ return -1;
+
+ /*
+ * Count how many boot images there are,
+ * and how many sectors they consume.
+ */
+ num_entries = 1;
+ used_sectors = 0;
+
+ TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) {
+ used_sectors += tmp_disk->num_sectors;
+
+ /* One default entry per image */
+ num_entries++;
+ }
+ catalog_sectors = howmany(num_entries * 0x20, diskStructure.sectorSize);
+ used_sectors += catalog_sectors;
+
+ if (diskStructure.verbose_level > 0) {
+ printf("%s: there will be %i entries consuming %i sectors. "
+ "Catalog is %i sectors\n", __func__, num_entries,
+ used_sectors, catalog_sectors);
+ }
+
+ /* Populate sector numbers */
+ sector = first_sector + catalog_sectors;
+ TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) {
+ tmp_disk->sector = sector;
+ sector += tmp_disk->num_sectors;
+ }
+
+ LIST_INSERT_HEAD(&diskStructure.boot_entries, valid_entry, ll_struct);
+
+ /* Step 1b: Initial/default entry */
+ /* TODO : PARAM */
+ tmp_disk = TAILQ_FIRST(&diskStructure.boot_images);
+ default_entry = cd9660_boot_setup_default_entry(tmp_disk);
+ if (default_entry == NULL) {
+ warnx("Error: memory allocation failed in cd9660_setup_boot");
+ return -1;
+ }
+
+ LIST_INSERT_AFTER(valid_entry, default_entry, ll_struct);
+
+ /* Todo: multiple default entries? */
+
+ tmp_disk = TAILQ_NEXT(tmp_disk, image_list);
+
+ temp = default_entry;
+
+ /* If multiple boot images are given : */
+ while (tmp_disk != NULL) {
+ /* Step 2: Section header */
+ switch (tmp_disk->system) {
+ case ET_SYS_X86:
+ headp = &x86_head;
+ break;
+ case ET_SYS_PPC:
+ headp = &ppc_head;
+ break;
+ case ET_SYS_MAC:
+ headp = &mac_head;
+ break;
+ default:
+ warnx("%s: internal error: unknown system type",
+ __func__);
+ return -1;
+ }
+
+ if (*headp == NULL) {
+ head =
+ cd9660_boot_setup_section_head(tmp_disk->system);
+ if (head == NULL) {
+ warnx("Error: memory allocation failed in "
+ "cd9660_setup_boot");
+ return -1;
+ }
+ LIST_INSERT_AFTER(default_entry, head, ll_struct);
+ *headp = head;
+ } else
+ head = *headp;
+
+ head->entry_data.SH.num_section_entries[0]++;
+
+ /* Step 2a: Section entry and extensions */
+ temp = cd9660_boot_setup_section_entry(tmp_disk);
+ if (temp == NULL) {
+ warn("%s: cd9660_boot_setup_section_entry", __func__);
+ return -1;
+ }
+
+ while ((next = LIST_NEXT(head, ll_struct)) != NULL &&
+ next->entry_type == ET_ENTRY_SE)
+ head = next;
+
+ LIST_INSERT_AFTER(head, temp, ll_struct);
+ tmp_disk = TAILQ_NEXT(tmp_disk, image_list);
+ }
+
+ /* TODO: Remaining boot disks when implemented */
+
+ return first_sector + used_sectors;
+}
+
+int
+cd9660_setup_boot_volume_descriptor(volume_descriptor *bvd)
+{
+ boot_volume_descriptor *bvdData =
+ (boot_volume_descriptor*)bvd->volumeDescriptorData;
+
+ bvdData->boot_record_indicator[0] = ISO_VOLUME_DESCRIPTOR_BOOT;
+ memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
+ bvdData->version[0] = 1;
+ memcpy(bvdData->boot_system_identifier, ET_ID, 23);
+ memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
+ diskStructure.boot_descriptor =
+ (boot_volume_descriptor*) bvd->volumeDescriptorData;
+ return 1;
+}
+
+int
+cd9660_write_boot(FILE *fd)
+{
+ struct boot_catalog_entry *e;
+ struct cd9660_boot_image *t;
+
+ /* write boot catalog */
+ if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector *
+ diskStructure.sectorSize, SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ if (diskStructure.verbose_level > 0) {
+ printf("Writing boot catalog to sector %" PRId64 "\n",
+ diskStructure.boot_catalog_sector);
+ }
+ LIST_FOREACH(e, &diskStructure.boot_entries, ll_struct) {
+ if (diskStructure.verbose_level > 0) {
+ printf("Writing catalog entry of type %d\n",
+ e->entry_type);
+ }
+ /*
+ * It doesnt matter which one gets written
+ * since they are the same size
+ */
+ fwrite(&(e->entry_data.VE), 1, 32, fd);
+ }
+ if (diskStructure.verbose_level > 0)
+ printf("Finished writing boot catalog\n");
+
+ /* copy boot images */
+ TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) {
+ if (diskStructure.verbose_level > 0) {
+ printf("Writing boot image from %s to sectors %d\n",
+ t->filename, t->sector);
+ }
+ cd9660_copy_file(fd, t->sector, t->filename);
+ }
+
+ return 0;
+}
diff --git a/usr.sbin/makefs/cd9660/cd9660_eltorito.h b/usr.sbin/makefs/cd9660/cd9660_eltorito.h
new file mode 100644
index 0000000..02f153d
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_eltorito.h
@@ -0,0 +1,164 @@
+/* $NetBSD: cd9660_eltorito.h,v 1.5 2009/07/04 14:31:38 ahoka Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (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$
+ */
+
+#ifndef _CD9660_ELTORITO_H_
+#define _CD9660_ELTORITO_H_
+
+/* Boot defines */
+#define ET_ID "EL TORITO SPECIFICATION"
+#define ET_SYS_X86 0
+#define ET_SYS_PPC 1
+#define ET_SYS_MAC 2
+
+#define ET_BOOT_ENTRY_SIZE 0x20
+
+#define ET_BOOTABLE 0x88
+#define ET_NOT_BOOTABLE 0
+
+#define ET_MEDIA_NOEM 0
+#define ET_MEDIA_12FDD 1
+#define ET_MEDIA_144FDD 2
+#define ET_MEDIA_288FDD 3
+#define ET_MEDIA_HDD 4
+
+#define ET_INDICATOR_HEADERMORE 0x90
+#define ET_INDICATOR_HEADERLAST 0x91
+#define ET_INDICATOR_EXTENSION 0x44
+
+/*** Boot Structures ***/
+
+typedef struct _boot_volume_descriptor {
+ u_char boot_record_indicator [ISODCL(0x00,0x00)];
+ u_char identifier [ISODCL(0x01,0x05)];
+ u_char version [ISODCL(0x06,0x06)];
+ u_char boot_system_identifier [ISODCL(0x07,0x26)];
+ u_char unused1 [ISODCL(0x27,0x46)];
+ u_char boot_catalog_pointer [ISODCL(0x47,0x4A)];
+ u_char unused2 [ISODCL(0x4B,0x7FF)];
+} boot_volume_descriptor;
+
+typedef struct _boot_catalog_validation_entry {
+ u_char header_id [ISODCL(0x00,0x00)];
+ u_char platform_id [ISODCL(0x01,0x01)];
+ u_char reserved1 [ISODCL(0x02,0x03)];
+ u_char manufacturer [ISODCL(0x04,0x1B)];
+ u_char checksum [ISODCL(0x1C,0x1D)];
+ u_char key [ISODCL(0x1E,0x1F)];
+} boot_catalog_validation_entry;
+
+typedef struct _boot_catalog_initial_entry {
+ u_char boot_indicator [ISODCL(0x00,0x00)];
+ u_char media_type [ISODCL(0x01,0x01)];
+ u_char load_segment [ISODCL(0x02,0x03)];
+ u_char system_type [ISODCL(0x04,0x04)];
+ u_char unused_1 [ISODCL(0x05,0x05)];
+ u_char sector_count [ISODCL(0x06,0x07)];
+ u_char load_rba [ISODCL(0x08,0x0B)];
+ u_char unused_2 [ISODCL(0x0C,0x1F)];
+} boot_catalog_initial_entry;
+
+#define ET_SECTION_HEADER_MORE 0x90
+#define ET_SECTION_HEADER_LAST 0x91
+
+typedef struct _boot_catalog_section_header {
+ u_char header_indicator [ISODCL(0x00,0x00)];
+ u_char platform_id [ISODCL(0x01,0x01)];
+ u_char num_section_entries [ISODCL(0x02,0x03)];
+ u_char id_string [ISODCL(0x04,0x1F)];
+} boot_catalog_section_header;
+
+typedef struct _boot_catalog_section_entry {
+ u_char boot_indicator [ISODCL(0x00,0x00)];
+ u_char media_type [ISODCL(0x01,0x01)];
+ u_char load_segment [ISODCL(0x02,0x03)];
+ u_char system_type [ISODCL(0x04,0x04)];
+ u_char unused_1 [ISODCL(0x05,0x05)];
+ u_char sector_count [ISODCL(0x06,0x07)];
+ u_char load_rba [ISODCL(0x08,0x0B)];
+ u_char selection_criteria [ISODCL(0x0C,0x0C)];
+ u_char vendor_criteria [ISODCL(0x0D,0x1F)];
+} boot_catalog_section_entry;
+
+typedef struct _boot_catalog_section_entry_extension {
+ u_char extension_indicator [ISODCL(0x00,0x00)];
+ u_char flags [ISODCL(0x01,0x01)];
+ u_char vendor_criteria [ISODCL(0x02,0x1F)];
+} boot_catalog_section_entry_extension;
+
+#define ET_ENTRY_VE 1
+#define ET_ENTRY_IE 2
+#define ET_ENTRY_SH 3
+#define ET_ENTRY_SE 4
+#define ET_ENTRY_EX 5
+
+struct boot_catalog_entry {
+ char entry_type;
+ union {
+ boot_catalog_validation_entry VE;
+ boot_catalog_initial_entry IE;
+ boot_catalog_section_header SH;
+ boot_catalog_section_entry SE;
+ boot_catalog_section_entry_extension EX;
+ } entry_data;
+
+ LIST_ENTRY(boot_catalog_entry) ll_struct;
+};
+
+/* Temporary structure */
+struct cd9660_boot_image {
+ char *filename;
+ int size;
+ int sector; /* copied to LoadRBA */
+ int num_sectors;
+ unsigned int loadSegment;
+ u_char targetMode;
+ u_char system;
+ u_char bootable;
+ /*
+ * If the boot image exists in the filesystem
+ * already, this is a pointer to that node. For the sake
+ * of simplicity in future versions, this pointer is only
+ * to the node in the primary volume. This SHOULD be done
+ * via a hashtable lookup.
+ */
+ struct _cd9660node *boot_image_node;
+ TAILQ_ENTRY(cd9660_boot_image) image_list;
+ int serialno;
+};
+
+
+#endif /* _CD9660_ELTORITO_H_ */
+
diff --git a/usr.sbin/makefs/cd9660/cd9660_strings.c b/usr.sbin/makefs/cd9660/cd9660_strings.c
new file mode 100644
index 0000000..7789c8e
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_strings.c
@@ -0,0 +1,120 @@
+/* $NetBSD: cd9660_strings.c,v 1.4 2007/01/16 17:32:05 hubertf Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#include <sys/mount.h>
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+#include <ctype.h>
+
+#include "makefs.h"
+#include "cd9660.h"
+
+
+void
+cd9660_uppercase_characters(char *str, int len)
+{
+ int p;
+
+ for (p = 0; p < len; p++) {
+ if (islower((unsigned char)str[p]) )
+ str[p] -= 32;
+ }
+}
+
+static inline int
+cd9660_is_a_char(char c)
+{
+ return (isupper((unsigned char)c)
+ || c == '_'
+ || (c >= '0' && c <= '?'));
+}
+
+static inline int
+cd9660_is_d_char(char c)
+{
+ return (isupper((unsigned char)c)
+ || c == '_'
+ || (c >= '%' && c <= '9')
+ || (c >= ' ' && c <= '\"'));
+}
+
+/*
+ * Test a string to see if it is composed of valid a characters
+ * @param const char* The string to test
+ * @returns int 1 if valid, 2 if valid if characters are converted to
+ * upper case, 0 otherwise
+ */
+int
+cd9660_valid_a_chars(const char *str)
+{
+ const char *c = str;
+ int upperFound = 0;
+
+ while ((*c) != '\0') {
+ if (!(cd9660_is_a_char(*c))) {
+ if (islower((unsigned char)*c) )
+ upperFound = 1;
+ else
+ return 0;
+ }
+ c++;
+ }
+ return upperFound + 1;
+}
+
+/*
+ * Test a string to see if it is composed of valid d characters
+ * @param const char* The string to test
+ * @returns int 1 if valid, 2 if valid if characters are converted to
+ * upper case, 0 otherwise
+ */
+int
+cd9660_valid_d_chars(const char *str)
+{
+ const char *c=str;
+ int upperFound = 0;
+
+ while ((*c) != '\0') {
+ if (!(cd9660_is_d_char(*c))) {
+ if (islower((unsigned char)*c) )
+ upperFound = 1;
+ else
+ return 0;
+ }
+ c++;
+ }
+ return upperFound + 1;
+}
diff --git a/usr.sbin/makefs/cd9660/cd9660_write.c b/usr.sbin/makefs/cd9660/cd9660_write.c
new file mode 100644
index 0000000..46d4a34
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/cd9660_write.c
@@ -0,0 +1,518 @@
+/* $NetBSD: cd9660_write.c,v 1.13 2010/10/22 00:49:15 christos Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#include "cd9660.h"
+#include "iso9660_rrip.h"
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+static int cd9660_write_volume_descriptors(FILE *);
+static int cd9660_write_path_table(FILE *, off_t, int);
+static int cd9660_write_path_tables(FILE *);
+static int cd9660_write_file(FILE *, cd9660node *);
+static int cd9660_write_filedata(FILE *, off_t, const unsigned char *, int);
+#if 0
+static int cd9660_write_buffered(FILE *, off_t, int, const unsigned char *);
+#endif
+static void cd9660_write_rr(FILE *, cd9660node *, off_t, off_t);
+
+/*
+ * Write the image
+ * Writes the entire image
+ * @param const char* The filename for the image
+ * @returns int 1 on success, 0 on failure
+ */
+int
+cd9660_write_image(const char* image)
+{
+ FILE *fd;
+ int status;
+ char buf[CD9660_SECTOR_SIZE];
+
+ if ((fd = fopen(image, "w+")) == NULL) {
+ err(EXIT_FAILURE, "%s: Can't open `%s' for writing", __func__,
+ image);
+ }
+
+ if (diskStructure.verbose_level > 0)
+ printf("Writing image\n");
+
+ if (diskStructure.has_generic_bootimage) {
+ status = cd9660_copy_file(fd, 0,
+ diskStructure.generic_bootimage);
+ if (status == 0) {
+ warnx("%s: Error writing generic boot image",
+ __func__);
+ goto cleanup_bad_image;
+ }
+ }
+
+ /* Write the volume descriptors */
+ status = cd9660_write_volume_descriptors(fd);
+ if (status == 0) {
+ warnx("%s: Error writing volume descriptors to image",
+ __func__);
+ goto cleanup_bad_image;
+ }
+
+ if (diskStructure.verbose_level > 0)
+ printf("Volume descriptors written\n");
+
+ /*
+ * Write the path tables: there are actually four, but right
+ * now we are only concearned with two.
+ */
+ status = cd9660_write_path_tables(fd);
+ if (status == 0) {
+ warnx("%s: Error writing path tables to image", __func__);
+ goto cleanup_bad_image;
+ }
+
+ if (diskStructure.verbose_level > 0)
+ printf("Path tables written\n");
+
+ /* Write the directories and files */
+ status = cd9660_write_file(fd, diskStructure.rootNode);
+ if (status == 0) {
+ warnx("%s: Error writing files to image", __func__);
+ goto cleanup_bad_image;
+ }
+
+ if (diskStructure.is_bootable) {
+ cd9660_write_boot(fd);
+ }
+
+ /* Write padding bits. This is temporary */
+ memset(buf, 0, CD9660_SECTOR_SIZE);
+ cd9660_write_filedata(fd, diskStructure.totalSectors - 1, buf, 1);
+
+ if (diskStructure.verbose_level > 0)
+ printf("Files written\n");
+ fclose(fd);
+
+ if (diskStructure.verbose_level > 0)
+ printf("Image closed\n");
+ return 1;
+
+cleanup_bad_image:
+ fclose(fd);
+ if (!diskStructure.keep_bad_images)
+ unlink(image);
+ if (diskStructure.verbose_level > 0)
+ printf("Bad image cleaned up\n");
+ return 0;
+}
+
+static int
+cd9660_write_volume_descriptors(FILE *fd)
+{
+ volume_descriptor *vd_temp = diskStructure.firstVolumeDescriptor;
+ int pos;
+
+ while (vd_temp != NULL) {
+ pos = vd_temp->sector * diskStructure.sectorSize;
+ cd9660_write_filedata(fd, vd_temp->sector,
+ vd_temp->volumeDescriptorData, 1);
+ vd_temp = vd_temp->next;
+ }
+ return 1;
+}
+
+/*
+ * Write out an individual path table
+ * Used just to keep redundant code to a minimum
+ * @param FILE *fd Valid file pointer
+ * @param int Sector to start writing path table to
+ * @param int Endian mode : BIG_ENDIAN or LITTLE_ENDIAN
+ * @returns int 1 on success, 0 on failure
+ */
+static int
+cd9660_write_path_table(FILE *fd, off_t sector, int mode)
+{
+ int path_table_sectors = CD9660_BLOCKS(diskStructure.sectorSize,
+ diskStructure.pathTableLength);
+ unsigned char *buffer;
+ unsigned char *buffer_head;
+ int len;
+ path_table_entry temp_entry;
+ cd9660node *ptcur;
+
+ buffer = malloc(diskStructure.sectorSize * path_table_sectors);
+ if (buffer == NULL) {
+ warnx("%s: Memory allocation error allocating buffer",
+ __func__);
+ return 0;
+ }
+ buffer_head = buffer;
+ memset(buffer, 0, diskStructure.sectorSize * path_table_sectors);
+
+ ptcur = diskStructure.rootNode;
+
+ while (ptcur != NULL) {
+ memset(&temp_entry, 0, sizeof(path_table_entry));
+ temp_entry.length[0] = ptcur->isoDirRecord->name_len[0];
+ temp_entry.extended_attribute_length[0] =
+ ptcur->isoDirRecord->ext_attr_length[0];
+ memcpy(temp_entry.name, ptcur->isoDirRecord->name,
+ temp_entry.length[0] + 1);
+
+ /* round up */
+ len = temp_entry.length[0] + 8 + (temp_entry.length[0] & 0x01);
+
+ /* todo: function pointers instead */
+ if (mode == LITTLE_ENDIAN) {
+ cd9660_731(ptcur->fileDataSector,
+ temp_entry.first_sector);
+ cd9660_721((ptcur->parent == NULL ?
+ 1 : ptcur->parent->ptnumber),
+ temp_entry.parent_number);
+ } else {
+ cd9660_732(ptcur->fileDataSector,
+ temp_entry.first_sector);
+ cd9660_722((ptcur->parent == NULL ?
+ 1 : ptcur->parent->ptnumber),
+ temp_entry.parent_number);
+ }
+
+
+ memcpy(buffer, &temp_entry, len);
+ buffer += len;
+
+ ptcur = ptcur->ptnext;
+ }
+
+ return cd9660_write_filedata(fd, sector, buffer_head,
+ path_table_sectors);
+}
+
+
+/*
+ * Write out the path tables to disk
+ * Each file descriptor should be pointed to by the PVD, so we know which
+ * sector to copy them to. One thing to watch out for: the only path tables
+ * stored are in the endian mode that the application is compiled for. So,
+ * the first thing to do is write out that path table, then to write the one
+ * in the other endian mode requires to convert the endianness of each entry
+ * in the table. The best way to do this would be to create a temporary
+ * path_table_entry structure, then for each path table entry, copy it to
+ * the temporary entry, translate, then copy that to disk.
+ *
+ * @param FILE* Valid file descriptor
+ * @returns int 0 on failure, 1 on success
+ */
+static int
+cd9660_write_path_tables(FILE *fd)
+{
+ if (cd9660_write_path_table(fd,
+ diskStructure.primaryLittleEndianTableSector, LITTLE_ENDIAN) == 0)
+ return 0;
+
+ if (cd9660_write_path_table(fd,
+ diskStructure.primaryBigEndianTableSector, BIG_ENDIAN) == 0)
+ return 0;
+
+ /* @TODO: handle remaining two path tables */
+ return 1;
+}
+
+/*
+ * Write a file to disk
+ * Writes a file, its directory record, and its data to disk
+ * This file is designed to be called RECURSIVELY, so initially call it
+ * with the root node. All of the records should store what sector the
+ * file goes in, so no computation should be necessary.
+ *
+ * @param int fd Valid file descriptor
+ * @param struct cd9660node* writenode Pointer to the file to be written
+ * @returns int 0 on failure, 1 on success
+ */
+static int
+cd9660_write_file(FILE *fd, cd9660node *writenode)
+{
+ char *buf;
+ char *temp_file_name;
+ int ret;
+ off_t working_sector;
+ int cur_sector_offset;
+ int written;
+ iso_directory_record_cd9660 temp_record;
+ cd9660node *temp;
+ int rv = 0;
+
+ /* Todo : clean up variables */
+
+ temp_file_name = malloc(CD9660MAXPATH + 1);
+ if (temp_file_name == NULL)
+ err(EXIT_FAILURE, "%s: malloc", __func__);
+
+ memset(temp_file_name, 0, CD9660MAXPATH + 1);
+
+ buf = malloc(diskStructure.sectorSize);
+ if (buf == NULL)
+ err(EXIT_FAILURE, "%s: malloc", __func__);
+
+ if ((writenode->level != 0) &&
+ !(writenode->node->type & S_IFDIR)) {
+ fsinode *inode = writenode->node->inode;
+ /* Only attempt to write unwritten files that have length. */
+ if ((inode->flags & FI_WRITTEN) != 0) {
+ INODE_WARNX(("%s: skipping written inode %d", __func__,
+ (int)inode->st.st_ino));
+ } else if (writenode->fileDataLength > 0) {
+ INODE_WARNX(("%s: writing inode %d blocks at %" PRIu32,
+ __func__, (int)inode->st.st_ino, inode->ino));
+ inode->flags |= FI_WRITTEN;
+ cd9660_compute_full_filename(writenode,
+ temp_file_name, 0);
+ ret = cd9660_copy_file(fd, writenode->fileDataSector,
+ temp_file_name);
+ if (ret == 0)
+ goto out;
+ }
+ } else {
+ /*
+ * Here is a new revelation that ECMA didnt explain
+ * (at least not well).
+ * ALL . and .. records store the name "\0" and "\1"
+ * resepctively. So, for each directory, we have to
+ * make a new node.
+ *
+ * This is where it gets kinda messy, since we have to
+ * be careful of sector boundaries
+ */
+ cur_sector_offset = 0;
+ working_sector = writenode->fileDataSector;
+ if (fseeko(fd, working_sector * diskStructure.sectorSize,
+ SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ /*
+ * Now loop over children, writing out their directory
+ * records - beware of sector boundaries
+ */
+ TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) {
+ /*
+ * Copy the temporary record and adjust its size
+ * if necessary
+ */
+ memcpy(&temp_record, temp->isoDirRecord,
+ sizeof(iso_directory_record_cd9660));
+
+ temp_record.length[0] =
+ cd9660_compute_record_size(temp);
+
+ if (temp_record.length[0] + cur_sector_offset >=
+ diskStructure.sectorSize) {
+ cur_sector_offset = 0;
+ working_sector++;
+
+ /* Seek to the next sector. */
+ if (fseeko(fd, working_sector *
+ diskStructure.sectorSize, SEEK_SET) == -1)
+ err(1, "fseeko");
+ }
+ /* Write out the basic ISO directory record */
+ written = fwrite(&temp_record, 1,
+ temp->isoDirRecord->length[0], fd);
+ if (diskStructure.rock_ridge_enabled) {
+ cd9660_write_rr(fd, temp,
+ cur_sector_offset, working_sector);
+ }
+ if (fseeko(fd, working_sector *
+ diskStructure.sectorSize + cur_sector_offset +
+ temp_record.length[0] - temp->su_tail_size,
+ SEEK_SET) == -1)
+ err(1, "fseeko");
+ if (temp->su_tail_size > 0)
+ fwrite(temp->su_tail_data, 1,
+ temp->su_tail_size, fd);
+ if (ferror(fd)) {
+ warnx("%s: write error", __func__);
+ goto out;
+ }
+ cur_sector_offset += temp_record.length[0];
+
+ }
+
+ /*
+ * Recurse on children.
+ */
+ TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) {
+ if ((ret = cd9660_write_file(fd, temp)) == 0)
+ goto out;
+ }
+ }
+ rv = 1;
+out:
+ free(temp_file_name);
+ free(buf);
+ return rv;
+}
+
+/*
+ * Wrapper function to write a buffer (one sector) to disk.
+ * Seeks and writes the buffer.
+ * NOTE: You dont NEED to use this function, but it might make your
+ * life easier if you have to write things that align to a sector
+ * (such as volume descriptors).
+ *
+ * @param int fd Valid file descriptor
+ * @param int sector Sector number to write to
+ * @param const unsigned char* Buffer to write. This should be the
+ * size of a sector, and if only a portion
+ * is written, the rest should be set to 0.
+ */
+static int
+cd9660_write_filedata(FILE *fd, off_t sector, const unsigned char *buf,
+ int numsecs)
+{
+ off_t curpos;
+ size_t success;
+
+ curpos = ftello(fd);
+
+ if (fseeko(fd, sector * diskStructure.sectorSize, SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ success = fwrite(buf, diskStructure.sectorSize * numsecs, 1, fd);
+
+ if (fseeko(fd, curpos, SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ if (success == 1)
+ success = diskStructure.sectorSize * numsecs;
+ return success;
+}
+
+#if 0
+static int
+cd9660_write_buffered(FILE *fd, off_t offset, int buff_len,
+ const unsigned char* buffer)
+{
+ static int working_sector = -1;
+ static char buf[CD9660_SECTOR_SIZE];
+
+ return 0;
+}
+#endif
+
+int
+cd9660_copy_file(FILE *fd, off_t start_sector, const char *filename)
+{
+ FILE *rf;
+ int bytes_read;
+ off_t sector = start_sector;
+ int buf_size = diskStructure.sectorSize;
+ char *buf;
+
+ buf = malloc(buf_size);
+ if (buf == NULL)
+ err(EXIT_FAILURE, "%s: malloc", __func__);
+
+ if ((rf = fopen(filename, "rb")) == NULL) {
+ warn("%s: cannot open %s", __func__, filename);
+ free(buf);
+ return 0;
+ }
+
+ if (diskStructure.verbose_level > 1)
+ printf("Writing file: %s\n",filename);
+
+ if (fseeko(fd, start_sector * diskStructure.sectorSize, SEEK_SET) == -1)
+ err(1, "fseeko");
+
+ while (!feof(rf)) {
+ bytes_read = fread(buf,1,buf_size,rf);
+ if (ferror(rf)) {
+ warn("%s: fread", __func__);
+ free(buf);
+ return 0;
+ }
+
+ fwrite(buf,1,bytes_read,fd);
+ if (ferror(fd)) {
+ warn("%s: fwrite", __func__);
+ free(buf);
+ return 0;
+ }
+ sector++;
+ }
+
+ fclose(rf);
+ free(buf);
+ return 1;
+}
+
+static void
+cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector)
+{
+ int in_ca = 0;
+ struct ISO_SUSP_ATTRIBUTES *myattr;
+
+ offset += writenode->isoDirRecord->length[0];
+ if (fseeko(fd, sector * diskStructure.sectorSize + offset, SEEK_SET) ==
+ -1)
+ err(1, "fseeko");
+ /* Offset now points at the end of the record */
+ TAILQ_FOREACH(myattr, &writenode->head, rr_ll) {
+ fwrite(&(myattr->attr), CD9660_SUSP_ENTRY_SIZE(myattr), 1, fd);
+
+ if (!in_ca) {
+ offset += CD9660_SUSP_ENTRY_SIZE(myattr);
+ if (myattr->last_in_suf) {
+ /*
+ * Point the offset to the start of this
+ * record's CE area
+ */
+ if (fseeko(fd, ((off_t)diskStructure.
+ susp_continuation_area_start_sector *
+ diskStructure.sectorSize)
+ + writenode->susp_entry_ce_start,
+ SEEK_SET) == -1)
+ err(1, "fseeko");
+ in_ca = 1;
+ }
+ }
+ }
+
+ /*
+ * If we had to go to the continuation area, head back to
+ * where we should be.
+ */
+ if (in_ca)
+ if (fseeko(fd, sector * diskStructure.sectorSize + offset,
+ SEEK_SET) == -1)
+ err(1, "fseeko");
+}
diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.c b/usr.sbin/makefs/cd9660/iso9660_rrip.c
new file mode 100644
index 0000000..71f77aa
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/iso9660_rrip.c
@@ -0,0 +1,836 @@
+/* $NetBSD: iso9660_rrip.c,v 1.8 2009/01/10 22:06:29 bjh21 Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (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 will hold all the function definitions
+ * defined in iso9660_rrip.h
+ */
+
+#include "makefs.h"
+#include "cd9660.h"
+#include "iso9660_rrip.h"
+#include <sys/queue.h>
+#include <stdio.h>
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+static void cd9660_rrip_initialize_inode(cd9660node *);
+static int cd9660_susp_handle_continuation(cd9660node *);
+static int cd9660_susp_handle_continuation_common(cd9660node *, int);
+
+int
+cd9660_susp_initialize(cd9660node *node, cd9660node *parent,
+ cd9660node *grandparent)
+{
+ cd9660node *cn;
+ int r;
+
+ /* Make sure the node is not NULL. If it is, there are major problems */
+ assert(node != NULL);
+
+ if (!(node->type & CD9660_TYPE_DOT) &&
+ !(node->type & CD9660_TYPE_DOTDOT))
+ TAILQ_INIT(&(node->head));
+ if (node->dot_record != 0)
+ TAILQ_INIT(&(node->dot_record->head));
+ if (node->dot_dot_record != 0)
+ TAILQ_INIT(&(node->dot_dot_record->head));
+
+ /* SUSP specific entries here */
+ if ((r = cd9660_susp_initialize_node(node)) < 0)
+ return r;
+
+ /* currently called cd9660node_rrip_init_links */
+ r = cd9660_rrip_initialize_node(node, parent, grandparent);
+ if (r < 0)
+ return r;
+
+ /*
+ * See if we need a CE record, and set all of the
+ * associated counters.
+ *
+ * This should be called after all extensions. After
+ * this is called, no new records should be added.
+ */
+ if ((r = cd9660_susp_handle_continuation(node)) < 0)
+ return r;
+
+ /* Recurse on children. */
+ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
+ if ((r = cd9660_susp_initialize(cn, node, parent)) < 0)
+ return 0;
+ }
+ return 1;
+}
+
+int
+cd9660_susp_finalize(cd9660node *node)
+{
+ cd9660node *temp;
+ int r;
+
+ assert(node != NULL);
+
+ if (node == diskStructure.rootNode)
+ diskStructure.susp_continuation_area_current_free = 0;
+
+ if ((r = cd9660_susp_finalize_node(node)) < 0)
+ return r;
+ if ((r = cd9660_rrip_finalize_node(node)) < 0)
+ return r;
+
+ TAILQ_FOREACH(temp, &node->cn_children, cn_next_child) {
+ if ((r = cd9660_susp_finalize(temp)) < 0)
+ return r;
+ }
+ return 1;
+}
+
+/*
+ * If we really wanted to speed things up, we could have some sort of
+ * lookup table on the SUSP entry type that calls a functor. Or, we could
+ * combine the functions. These functions are kept separate to allow
+ * easier addition of other extensions.
+
+ * For the sake of simplicity and clarity, we won't be doing that for now.
+ */
+
+/*
+ * SUSP needs to update the following types:
+ * CE (continuation area)
+ */
+int
+cd9660_susp_finalize_node(cd9660node *node)
+{
+ struct ISO_SUSP_ATTRIBUTES *t;
+
+ /* Handle CE counters */
+ if (node->susp_entry_ce_length > 0) {
+ node->susp_entry_ce_start =
+ diskStructure.susp_continuation_area_current_free;
+ diskStructure.susp_continuation_area_current_free +=
+ node->susp_entry_ce_length;
+ }
+
+ TAILQ_FOREACH(t, &node->head, rr_ll) {
+ if (t->susp_type != SUSP_TYPE_SUSP ||
+ t->entry_type != SUSP_ENTRY_SUSP_CE)
+ continue;
+ cd9660_bothendian_dword(
+ diskStructure.
+ susp_continuation_area_start_sector,
+ t->attr.su_entry.CE.ca_sector);
+
+ cd9660_bothendian_dword(
+ diskStructure.
+ susp_continuation_area_start_sector,
+ t->attr.su_entry.CE.ca_sector);
+ cd9660_bothendian_dword(node->susp_entry_ce_start,
+ t->attr.su_entry.CE.offset);
+ cd9660_bothendian_dword(node->susp_entry_ce_length,
+ t->attr.su_entry.CE.length);
+ }
+ return 0;
+}
+
+int
+cd9660_rrip_finalize_node(cd9660node *node)
+{
+ struct ISO_SUSP_ATTRIBUTES *t;
+
+ TAILQ_FOREACH(t, &node->head, rr_ll) {
+ if (t->susp_type != SUSP_TYPE_RRIP)
+ continue;
+ switch (t->entry_type) {
+ case SUSP_ENTRY_RRIP_CL:
+ /* Look at rr_relocated*/
+ if (node->rr_relocated == NULL)
+ return -1;
+ cd9660_bothendian_dword(
+ node->rr_relocated->fileDataSector,
+ (unsigned char *)
+ t->attr.rr_entry.CL.dir_loc);
+ break;
+ case SUSP_ENTRY_RRIP_PL:
+ /* Look at rr_real_parent */
+ if (node->rr_real_parent == NULL)
+ return -1;
+ cd9660_bothendian_dword(
+ node->rr_real_parent->fileDataSector,
+ (unsigned char *)
+ t->attr.rr_entry.PL.dir_loc);
+ break;
+ }
+ }
+ return 0;
+}
+
+static int
+cd9660_susp_handle_continuation_common(cd9660node *node, int space)
+{
+ int ca_used, susp_used, susp_used_pre_ce, working;
+ struct ISO_SUSP_ATTRIBUTES *temp, *pre_ce, *last, *CE, *ST;
+
+ pre_ce = last = NULL;
+ working = 254 - space;
+ if (node->su_tail_size > 0)
+ /* Allow 4 bytes for "ST" record. */
+ working -= node->su_tail_size + 4;
+ /* printf("There are %i bytes to work with\n",working); */
+
+ susp_used_pre_ce = susp_used = 0;
+ ca_used = 0;
+ TAILQ_FOREACH(temp, &node->head, rr_ll) {
+ if (working < 0)
+ break;
+ /*
+ * printf("SUSP Entry found, length is %i\n",
+ * CD9660_SUSP_ENTRY_SIZE(temp));
+ */
+ working -= CD9660_SUSP_ENTRY_SIZE(temp);
+ if (working >= 0) {
+ last = temp;
+ susp_used += CD9660_SUSP_ENTRY_SIZE(temp);
+ }
+ if (working >= 28) {
+ /*
+ * Remember the last entry after which we
+ * could insert a "CE" entry.
+ */
+ pre_ce = last;
+ susp_used_pre_ce = susp_used;
+ }
+ }
+
+ /* A CE entry is needed */
+ if (working <= 0) {
+ CE = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
+ SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY);
+ cd9660_susp_ce(CE, node);
+ /* This will automatically insert at the appropriate location */
+ if (pre_ce != NULL)
+ TAILQ_INSERT_AFTER(&node->head, pre_ce, CE, rr_ll);
+ else
+ TAILQ_INSERT_HEAD(&node->head, CE, rr_ll);
+ last = CE;
+ susp_used = susp_used_pre_ce + 28;
+ /* Count how much CA data is necessary */
+ for (temp = TAILQ_NEXT(last, rr_ll); temp != NULL;
+ temp = TAILQ_NEXT(temp, rr_ll)) {
+ ca_used += CD9660_SUSP_ENTRY_SIZE(temp);
+ }
+ }
+
+ /* An ST entry is needed */
+ if (node->su_tail_size > 0) {
+ ST = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
+ SUSP_ENTRY_SUSP_ST, "ST", SUSP_LOC_ENTRY);
+ cd9660_susp_st(ST, node);
+ if (last != NULL)
+ TAILQ_INSERT_AFTER(&node->head, last, ST, rr_ll);
+ else
+ TAILQ_INSERT_HEAD(&node->head, ST, rr_ll);
+ last = ST;
+ susp_used += 4;
+ }
+ if (last != NULL)
+ last->last_in_suf = 1;
+
+ node->susp_entry_size = susp_used;
+ node->susp_entry_ce_length = ca_used;
+
+ diskStructure.susp_continuation_area_size += ca_used;
+ return 1;
+}
+
+/* See if a continuation entry is needed for each of the different types */
+static int
+cd9660_susp_handle_continuation(cd9660node *node)
+{
+ assert (node != NULL);
+
+ /* Entry */
+ if (cd9660_susp_handle_continuation_common(
+ node,(int)(node->isoDirRecord->length[0])) < 0)
+ return 0;
+
+ return 1;
+}
+
+int
+cd9660_susp_initialize_node(cd9660node *node)
+{
+ struct ISO_SUSP_ATTRIBUTES *temp;
+
+ /*
+ * Requirements/notes:
+ * CE: is added for us where needed
+ * ST: not sure if it is even required, but if so, should be
+ * handled by the CE code
+ * PD: isnt needed (though might be added for testing)
+ * SP: is stored ONLY on the . record of the root directory
+ * ES: not sure
+ */
+
+ /* Check for root directory, add SP and ER if needed. */
+ if (node->type & CD9660_TYPE_DOT) {
+ if (node->parent == diskStructure.rootNode) {
+ temp = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
+ SUSP_ENTRY_SUSP_SP, "SP", SUSP_LOC_DOT);
+ cd9660_susp_sp(temp, node);
+
+ /* Should be first entry. */
+ TAILQ_INSERT_HEAD(&node->head, temp, rr_ll);
+ }
+ }
+ return 1;
+}
+
+static void
+cd9660_rrip_initialize_inode(cd9660node *node)
+{
+ struct ISO_SUSP_ATTRIBUTES *attr;
+
+ /*
+ * Inode dependent values - this may change,
+ * but for now virtual files and directories do
+ * not have an inode structure
+ */
+
+ if ((node->node != NULL) && (node->node->inode != NULL)) {
+ /* PX - POSIX attributes */
+ attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
+ cd9660node_rrip_px(attr, node->node);
+
+ TAILQ_INSERT_TAIL(&node->head, attr, rr_ll);
+
+ /* TF - timestamp */
+ attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_TF, "TF", SUSP_LOC_ENTRY);
+ cd9660node_rrip_tf(attr, node->node);
+ TAILQ_INSERT_TAIL(&node->head, attr, rr_ll);
+
+ /* SL - Symbolic link */
+ /* ?????????? Dan - why is this here? */
+ if (TAILQ_EMPTY(&node->cn_children) &&
+ node->node->inode != NULL &&
+ S_ISLNK(node->node->inode->st.st_mode))
+ cd9660_createSL(node);
+
+ /* PN - device number */
+ if (node->node->inode != NULL &&
+ ((S_ISCHR(node->node->inode->st.st_mode) ||
+ S_ISBLK(node->node->inode->st.st_mode)))) {
+ attr =
+ cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_PN, "PN",
+ SUSP_LOC_ENTRY);
+ cd9660node_rrip_pn(attr, node->node);
+ TAILQ_INSERT_TAIL(&node->head, attr, rr_ll);
+ }
+ }
+}
+
+int
+cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent,
+ cd9660node *grandparent)
+{
+ struct ISO_SUSP_ATTRIBUTES *current = NULL;
+
+ assert(node != NULL);
+
+ if (node->type & CD9660_TYPE_DOT) {
+ /*
+ * Handle ER - should be the only entry to appear on
+ * a "." record
+ */
+ if (node->parent == diskStructure.rootNode) {
+ cd9660_susp_ER(node, 1, SUSP_RRIP_ER_EXT_ID,
+ SUSP_RRIP_ER_EXT_DES, SUSP_RRIP_ER_EXT_SRC);
+ }
+ if (parent != NULL && parent->node != NULL &&
+ parent->node->inode != NULL) {
+ /* PX - POSIX attributes */
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
+ cd9660node_rrip_px(current, parent->node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ }
+ } else if (node->type & CD9660_TYPE_DOTDOT) {
+ if (grandparent != NULL && grandparent->node != NULL &&
+ grandparent->node->inode != NULL) {
+ /* PX - POSIX attributes */
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
+ cd9660node_rrip_px(current, grandparent->node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ }
+ } else {
+ cd9660_rrip_initialize_inode(node);
+
+ /*
+ * Not every node needs a NM set - only if the name is
+ * actually different. IE: If a file is TEST -> TEST,
+ * no NM. test -> TEST, need a NM
+ *
+ * The rr_moved_dir needs to be assigned a NM record as well.
+ */
+ if (node == diskStructure.rr_moved_dir) {
+ cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME);
+ }
+ else if ((node->node != NULL) &&
+ ((strlen(node->node->name) !=
+ (int)node->isoDirRecord->name_len[0]) ||
+ (memcmp(node->node->name,node->isoDirRecord->name,
+ (int) node->isoDirRecord->name_len[0]) != 0))) {
+ cd9660_rrip_NM(node);
+ }
+
+
+
+ /* Rock ridge directory relocation code here. */
+
+ /* First handle the CL for the placeholder file. */
+ if (node->rr_relocated != NULL) {
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_CL, "CL", SUSP_LOC_ENTRY);
+ cd9660_rrip_CL(current, node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ }
+
+ /* Handle RE*/
+ if (node->rr_real_parent != NULL) {
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_RE, "RE", SUSP_LOC_ENTRY);
+ cd9660_rrip_RE(current,node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+
+ /* Handle PL */
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_PL, "PL", SUSP_LOC_DOTDOT);
+ cd9660_rrip_PL(current,node->dot_dot_record);
+ TAILQ_INSERT_TAIL(&node->dot_dot_record->head, current,
+ rr_ll);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ }
+ }
+ return 1;
+}
+
+struct ISO_SUSP_ATTRIBUTES*
+cd9660node_susp_create_node(int susp_type, int entry_type, const char *type_id,
+ int write_loc)
+{
+ struct ISO_SUSP_ATTRIBUTES* temp;
+
+ if ((temp = malloc(sizeof(struct ISO_SUSP_ATTRIBUTES))) == NULL) {
+ CD9660_MEM_ALLOC_ERROR("cd9660node_susp_create_node");
+ exit(1);
+ }
+
+ temp->susp_type = susp_type;
+ temp->entry_type = entry_type;
+ temp->last_in_suf = 0;
+ /* Phase this out */
+ temp->type_of[0] = type_id[0];
+ temp->type_of[1] = type_id[1];
+ temp->write_location = write_loc;
+
+ /*
+ * Since the first four bytes is common, lets go ahead and
+ * set the type identifier, since we are passing that to this
+ * function anyhow.
+ */
+ temp->attr.su_entry.SP.h.type[0] = type_id[0];
+ temp->attr.su_entry.SP.h.type[1] = type_id[1];
+ return temp;
+}
+
+int
+cd9660_rrip_PL(struct ISO_SUSP_ATTRIBUTES* p, cd9660node *node __unused)
+{
+ p->attr.rr_entry.PL.h.length[0] = 12;
+ p->attr.rr_entry.PL.h.version[0] = 1;
+ return 1;
+}
+
+int
+cd9660_rrip_CL(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *node __unused)
+{
+ p->attr.rr_entry.CL.h.length[0] = 12;
+ p->attr.rr_entry.CL.h.version[0] = 1;
+ return 1;
+}
+
+int
+cd9660_rrip_RE(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *node __unused)
+{
+ p->attr.rr_entry.RE.h.length[0] = 0;
+ p->attr.rr_entry.RE.h.version[0] = 1;
+ return 1;
+}
+
+void
+cd9660_createSL(cd9660node *node)
+{
+ struct ISO_SUSP_ATTRIBUTES* current;
+ int path_count, dir_count, done, i, j, dir_copied;
+ char temp_cr[255];
+ char temp_sl[255]; /* used in copying continuation entry*/
+ char* sl_ptr;
+
+ sl_ptr = node->node->symlink;
+
+ done = 0;
+ path_count = 0;
+ dir_count = 0;
+ dir_copied = 0;
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_SL, "SL", SUSP_LOC_ENTRY);
+
+ current->attr.rr_entry.SL.h.version[0] = 1;
+ current->attr.rr_entry.SL.flags[0] = SL_FLAGS_NONE;
+
+ if (*sl_ptr == '/') {
+ temp_cr[0] = SL_FLAGS_ROOT;
+ temp_cr[1] = 0;
+ memcpy(current->attr.rr_entry.SL.component + path_count,
+ temp_cr, 2);
+ path_count += 2;
+ sl_ptr++;
+ }
+
+ for (i = 0; i < (dir_count + 2); i++)
+ temp_cr[i] = '\0';
+
+ while (!done) {
+ while ((*sl_ptr != '/') && (*sl_ptr != '\0')) {
+ dir_copied = 1;
+ if (*sl_ptr == '.') {
+ if ((*(sl_ptr + 1) == '/') || (*(sl_ptr + 1)
+ == '\0')) {
+ temp_cr[0] = SL_FLAGS_CURRENT;
+ sl_ptr++;
+ } else if(*(sl_ptr + 1) == '.') {
+ if ((*(sl_ptr + 2) == '/') ||
+ (*(sl_ptr + 2) == '\0')) {
+ temp_cr[0] = SL_FLAGS_PARENT;
+ sl_ptr += 2;
+ }
+ } else {
+ temp_cr[dir_count+2] = *sl_ptr;
+ sl_ptr++;
+ dir_count++;
+ }
+ } else {
+ temp_cr[dir_count + 2] = *sl_ptr;
+ sl_ptr++;
+ dir_count++;
+ }
+ }
+
+ if ((path_count + dir_count) >= 249) {
+ current->attr.rr_entry.SL.flags[0] |= SL_FLAGS_CONTINUE;
+
+ j = 0;
+
+ if (path_count <= 249) {
+ while(j != (249 - path_count)) {
+ temp_sl[j] = temp_cr[j];
+ j++;
+ }
+ temp_sl[0] = SL_FLAGS_CONTINUE;
+ temp_sl[1] = j - 2;
+ memcpy(
+ current->attr.rr_entry.SL.component +
+ path_count,
+ temp_sl, j);
+ }
+
+ path_count += j;
+ current->attr.rr_entry.SL.h.length[0] = path_count + 5;
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ current= cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_SL, "SL", SUSP_LOC_ENTRY);
+ current->attr.rr_entry.SL.h.version[0] = 1;
+ current->attr.rr_entry.SL.flags[0] = SL_FLAGS_NONE;
+
+ path_count = 0;
+
+ if (dir_count > 2) {
+ while (j != dir_count + 2) {
+ current->attr.rr_entry.SL.component[
+ path_count + 2] = temp_cr[j];
+ j++;
+ path_count++;
+ }
+ current->attr.rr_entry.SL.component[1]
+ = path_count;
+ path_count+= 2;
+ } else {
+ while(j != dir_count) {
+ current->attr.rr_entry.SL.component[
+ path_count+2] = temp_cr[j];
+ j++;
+ path_count++;
+ }
+ }
+ } else {
+ if (dir_copied == 1) {
+ temp_cr[1] = dir_count;
+ memcpy(current->attr.rr_entry.SL.component +
+ path_count,
+ temp_cr, dir_count + 2);
+ path_count += dir_count + 2;
+ }
+ }
+
+ if (*sl_ptr == '\0') {
+ done = 1;
+ current->attr.rr_entry.SL.h.length[0] = path_count + 5;
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+ } else {
+ sl_ptr++;
+ dir_count = 0;
+ dir_copied = 0;
+ for(i = 0; i < 255; i++) {
+ temp_cr[i] = '\0';
+ }
+ }
+ }
+}
+
+int
+cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo)
+{
+ v->attr.rr_entry.PX.h.length[0] = 36;
+ v->attr.rr_entry.PX.h.version[0] = 1;
+ cd9660_bothendian_dword(pxinfo->inode->st.st_mode,
+ v->attr.rr_entry.PX.mode);
+ cd9660_bothendian_dword(pxinfo->inode->st.st_nlink,
+ v->attr.rr_entry.PX.links);
+ cd9660_bothendian_dword(pxinfo->inode->st.st_uid,
+ v->attr.rr_entry.PX.uid);
+ cd9660_bothendian_dword(pxinfo->inode->st.st_gid,
+ v->attr.rr_entry.PX.gid);
+
+ /* Ignoring the serial number for now */
+ return 1;
+}
+
+int
+cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *pn_field, fsnode *fnode)
+{
+ pn_field->attr.rr_entry.PN.h.length[0] = 20;
+ pn_field->attr.rr_entry.PN.h.version[0] = 1;
+
+ if (sizeof (fnode->inode->st.st_dev) > 32)
+ cd9660_bothendian_dword((uint64_t)fnode->inode->st.st_dev >> 32,
+ pn_field->attr.rr_entry.PN.high);
+ else
+ cd9660_bothendian_dword(0, pn_field->attr.rr_entry.PN.high);
+
+ cd9660_bothendian_dword(fnode->inode->st.st_dev & 0xffffffff,
+ pn_field->attr.rr_entry.PN.low);
+ return 1;
+}
+
+#if 0
+int
+cd9660node_rrip_nm(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *file_node)
+{
+ int nm_length = strlen(file_node->isoDirRecord->name) + 5;
+ p->attr.rr_entry.NM.h.type[0] = 'N';
+ p->attr.rr_entry.NM.h.type[1] = 'M';
+ sprintf(p->attr.rr_entry.NM.altname, "%s", file_node->isoDirRecord->name);
+ p->attr.rr_entry.NM.h.length[0] = (unsigned char)nm_length;
+ p->attr.rr_entry.NM.h.version[0] = (unsigned char)1;
+ p->attr.rr_entry.NM.flags[0] = (unsigned char) NM_PARENT;
+ return 1;
+}
+#endif
+
+int
+cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *p, fsnode *_node)
+{
+ p->attr.rr_entry.TF.flags[0] = TF_MODIFY | TF_ACCESS | TF_ATTRIBUTES;
+ p->attr.rr_entry.TF.h.length[0] = 4;
+ p->attr.rr_entry.TF.h.version[0] = 1;
+
+ /*
+ * Need to add creation time, backup time,
+ * expiration time, and effective time.
+ */
+
+ cd9660_time_915(p->attr.rr_entry.TF.timestamp,
+ _node->inode->st.st_atime);
+ p->attr.rr_entry.TF.h.length[0] += 7;
+
+ cd9660_time_915(p->attr.rr_entry.TF.timestamp + 7,
+ _node->inode->st.st_mtime);
+ p->attr.rr_entry.TF.h.length[0] += 7;
+
+ cd9660_time_915(p->attr.rr_entry.TF.timestamp + 14,
+ _node->inode->st.st_ctime);
+ p->attr.rr_entry.TF.h.length[0] += 7;
+ return 1;
+}
+
+int
+cd9660_susp_sp(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *spinfo __unused)
+{
+ p->attr.su_entry.SP.h.length[0] = 7;
+ p->attr.su_entry.SP.h.version[0] = 1;
+ p->attr.su_entry.SP.check[0] = 0xBE;
+ p->attr.su_entry.SP.check[1] = 0xEF;
+ p->attr.su_entry.SP.len_skp[0] = 0;
+ return 1;
+}
+
+int
+cd9660_susp_st(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *stinfo __unused)
+{
+ p->attr.su_entry.ST.h.type[0] = 'S';
+ p->attr.su_entry.ST.h.type[1] = 'T';
+ p->attr.su_entry.ST.h.length[0] = 4;
+ p->attr.su_entry.ST.h.version[0] = 1;
+ return 1;
+}
+
+int
+cd9660_susp_ce(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *spinfo __unused)
+{
+ p->attr.su_entry.CE.h.length[0] = 28;
+ p->attr.su_entry.CE.h.version[0] = 1;
+ /* Other attributes dont matter right now, will be updated later */
+ return 1;
+}
+
+int
+cd9660_susp_pd(struct ISO_SUSP_ATTRIBUTES *p __unused, int length __unused)
+{
+ return 1;
+}
+
+void
+cd9660_rrip_add_NM(cd9660node *node, const char *name)
+{
+ int working,len;
+ const char *p;
+ struct ISO_SUSP_ATTRIBUTES *r;
+
+ /*
+ * Each NM record has 254 byes to work with. This means that
+ * the name data itself only has 249 bytes to work with. So, a
+ * name with 251 characters would require two nm records.
+ */
+ p = name;
+ working = 1;
+ while (working) {
+ r = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_NM, "NM", SUSP_LOC_ENTRY);
+ r->attr.rr_entry.NM.h.version[0] = 1;
+ r->attr.rr_entry.NM.flags[0] = RRIP_NM_FLAGS_NONE;
+ len = strlen(p);
+
+ if (len > 249) {
+ len = 249;
+ r->attr.rr_entry.NM.flags[0] = RRIP_NM_FLAGS_CONTINUE;
+ } else {
+ working = 0;
+ }
+ memcpy(r->attr.rr_entry.NM.altname, p, len);
+ r->attr.rr_entry.NM.h.length[0] = 5 + len;
+
+ TAILQ_INSERT_TAIL(&node->head, r, rr_ll);
+
+ p += len;
+ }
+}
+
+void
+cd9660_rrip_NM(cd9660node *node)
+{
+ cd9660_rrip_add_NM(node, node->node->name);
+}
+
+struct ISO_SUSP_ATTRIBUTES*
+cd9660_susp_ER(cd9660node *node,
+ u_char ext_version, const char* ext_id, const char* ext_des,
+ const char* ext_src)
+{
+ int l;
+ struct ISO_SUSP_ATTRIBUTES *r;
+
+ r = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
+ SUSP_ENTRY_SUSP_ER, "ER", SUSP_LOC_DOT);
+
+ /* Fixed data is 8 bytes */
+ r->attr.su_entry.ER.h.length[0] = 8;
+ r->attr.su_entry.ER.h.version[0] = 1;
+
+ r->attr.su_entry.ER.len_id[0] = (u_char)strlen(ext_id);
+ r->attr.su_entry.ER.len_des[0] = (u_char)strlen(ext_des);
+ r->attr.su_entry.ER.len_src[0] = (u_char)strlen(ext_src);
+
+ l = r->attr.su_entry.ER.len_id[0] +
+ r->attr.su_entry.ER.len_src[0] +
+ r->attr.su_entry.ER.len_des[0];
+
+ /* Everything must fit. */
+ assert(l + r->attr.su_entry.ER.h.length[0] <= 254);
+
+ r->attr.su_entry.ER.h.length[0] += (u_char)l;
+
+
+ r->attr.su_entry.ER.ext_ver[0] = ext_version;
+ memcpy(r->attr.su_entry.ER.ext_data, ext_id,
+ (int)r->attr.su_entry.ER.len_id[0]);
+ l = (int) r->attr.su_entry.ER.len_id[0];
+ memcpy(r->attr.su_entry.ER.ext_data + l,ext_des,
+ (int)r->attr.su_entry.ER.len_des[0]);
+
+ l += (int)r->attr.su_entry.ER.len_des[0];
+ memcpy(r->attr.su_entry.ER.ext_data + l,ext_src,
+ (int)r->attr.su_entry.ER.len_src[0]);
+
+ TAILQ_INSERT_TAIL(&node->head, r, rr_ll);
+ return r;
+}
+
+struct ISO_SUSP_ATTRIBUTES*
+cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES *last __unused, cd9660node *node __unused)
+{
+ return NULL;
+}
diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.h b/usr.sbin/makefs/cd9660/iso9660_rrip.h
new file mode 100644
index 0000000..3653ac6
--- /dev/null
+++ b/usr.sbin/makefs/cd9660/iso9660_rrip.h
@@ -0,0 +1,290 @@
+/* $NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $ */
+
+/*
+ * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
+ * Perez-Rathke and Ram Vedam. All rights reserved.
+ *
+ * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
+ * Alan Perez-Rathke and Ram Vedam.
+ *
+ * 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 DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
+ * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (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$
+ */
+#ifndef __ISO9660_RRIP_H__
+#define __ISO9660_RRIP_H__
+
+/*
+ * This will hold all the functions needed to
+ * write an ISO 9660 image with Rock Ridge Extensions
+ */
+
+/* For writing must use ISO_RRIP_EXTREF structure */
+
+#include "makefs.h"
+#include <cd9660_rrip.h>
+#include "cd9660.h"
+#include <sys/queue.h>
+
+#define PX_LENGTH 0x2C
+#define PN_LENGTH 0x14
+#define TF_CREATION 0x00
+#define TF_MODIFY 0x01
+#define TF_ACCESS 0x02
+#define TF_ATTRIBUTES 0x04
+#define TF_BACKUP 0x08
+#define TF_EXPIRATION 0x10
+#define TF_EFFECTIVE 0x20
+#define TF_LONGFORM 0x40
+#define NM_CONTINUE 0x80
+#define NM_CURRENT 0x100
+#define NM_PARENT 0x200
+
+
+#define SUSP_LOC_ENTRY 0x01
+#define SUSP_LOC_DOT 0x02
+#define SUSP_LOC_DOTDOT 0x04
+
+#define SUSP_TYPE_SUSP 1
+#define SUSP_TYPE_RRIP 2
+
+#define SUSP_ENTRY_SUSP_CE 1
+#define SUSP_ENTRY_SUSP_PD 2
+#define SUSP_ENTRY_SUSP_SP 3
+#define SUSP_ENTRY_SUSP_ST 4
+#define SUSP_ENTRY_SUSP_ER 5
+#define SUSP_ENTRY_SUSP_ES 6
+
+#define SUSP_ENTRY_RRIP_PX 1
+#define SUSP_ENTRY_RRIP_PN 2
+#define SUSP_ENTRY_RRIP_SL 3
+#define SUSP_ENTRY_RRIP_NM 4
+#define SUSP_ENTRY_RRIP_CL 5
+#define SUSP_ENTRY_RRIP_PL 6
+#define SUSP_ENTRY_RRIP_RE 7
+#define SUSP_ENTRY_RRIP_TF 8
+#define SUSP_ENTRY_RRIP_SF 9
+
+#define SUSP_RRIP_ER_EXT_ID "IEEE_P1282"
+#define SUSP_RRIP_ER_EXT_DES "THE IEEE P1282 PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS."
+#define SUSP_RRIP_ER_EXT_SRC "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, PISCATAWAY, NJ, USA FOR THE P1282 SPECIFICATION."
+
+#define SL_FLAGS_NONE 0
+#define SL_FLAGS_CONTINUE 1
+#define SL_FLAGS_CURRENT 2
+#define SL_FLAGS_PARENT 4
+#define SL_FLAGS_ROOT 8
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char mode [ISODCL(5,12)];
+ u_char links [ISODCL(13,20)];
+ u_char uid [ISODCL(21,28)];
+ u_char gid [ISODCL(29,36)];
+ u_char serial [ISODCL(37,44)];/* Not used */
+} ISO_RRIP_PX;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char high [ISODCL(5,12)];
+ u_char low [ISODCL(13,20)];
+} ISO_RRIP_PN;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char flags [ISODCL ( 4, 4)];
+ u_char component [ISODCL ( 4, 256)];
+ u_int nBytes;
+} ISO_RRIP_SL;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char flags [ISODCL ( 4, 4)];
+ u_char timestamp [ISODCL ( 5, 256)];
+} ISO_RRIP_TF;
+
+#define RRIP_NM_FLAGS_NONE 0x00
+#define RRIP_NM_FLAGS_CONTINUE 0x01
+#define RRIP_NM_FLAGS_CURRENT 0x02
+#define RRIP_NM_FLAGS_PARENT 0x04
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char flags [ISODCL ( 4, 4)];
+ u_char altname [ISODCL ( 4, 256)];
+} ISO_RRIP_NM;
+
+/* Note that this is the same structure as cd9660_rrip.h : ISO_RRIP_CONT */
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char ca_sector [ISODCL ( 5, 12)];
+ u_char offset [ISODCL ( 13, 20)];
+ u_char length [ISODCL ( 21, 28)];
+} ISO_SUSP_CE;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char padding_area [ISODCL ( 4, 256)];
+} ISO_SUSP_PD;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char check [ISODCL ( 4, 5)];
+ u_char len_skp [ISODCL ( 6, 6)];
+} ISO_SUSP_SP;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+} ISO_SUSP_ST;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char len_id [ISODCL ( 4, 4)];
+ u_char len_des [ISODCL ( 5, 5)];
+ u_char len_src [ISODCL ( 6, 6)];
+ u_char ext_ver [ISODCL ( 7, 7)];
+ u_char ext_data [ISODCL (8,256)];
+/* u_char ext_id [ISODCL ( 8, 256)];
+ u_char ext_des [ISODCL ( 257, 513)];
+ u_char ext_src [ISODCL ( 514, 770)];*/
+} ISO_SUSP_ER;
+
+typedef struct {
+ ISO_SUSP_HEADER h;
+ u_char ext_seq [ISODCL ( 4, 4)];
+} ISO_SUSP_ES;
+
+typedef union {
+ ISO_RRIP_PX PX;
+ ISO_RRIP_PN PN;
+ ISO_RRIP_SL SL;
+ ISO_RRIP_NM NM;
+ ISO_RRIP_CLINK CL;
+ ISO_RRIP_PLINK PL;
+ ISO_RRIP_RELDIR RE;
+ ISO_RRIP_TF TF;
+} rrip_entry;
+
+typedef union {
+ ISO_SUSP_CE CE;
+ ISO_SUSP_PD PD;
+ ISO_SUSP_SP SP;
+ ISO_SUSP_ST ST;
+ ISO_SUSP_ER ER;
+ ISO_SUSP_ES ES;
+} susp_entry;
+
+typedef union {
+ susp_entry su_entry;
+ rrip_entry rr_entry;
+} SUSP_ENTRIES;
+
+struct ISO_SUSP_ATTRIBUTES {
+ SUSP_ENTRIES attr;
+ int type;
+ char type_of[2];
+ char last_in_suf; /* last entry in the System Use Field? */
+ /* Dan's addons - will merge later. This allows use of a switch */
+ char susp_type; /* SUSP or RRIP */
+ char entry_type; /* Record type */
+ char write_location;
+ TAILQ_ENTRY(ISO_SUSP_ATTRIBUTES) rr_ll;
+};
+
+#define CD9660_SUSP_ENTRY_SIZE(entry)\
+ ((int) ((entry)->attr.su_entry.SP.h.length[0]))
+
+/* Recursive function - move later to func pointer code*/
+int cd9660_susp_finalize(cd9660node *);
+
+/* These two operate on single nodes */
+int cd9660_susp_finalize_node(cd9660node *);
+int cd9660_rrip_finalize_node(cd9660node *);
+
+/* POSIX File attribute */
+int cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
+
+/* Device number */
+int cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
+
+/* Symbolic link */
+int cd9660node_rrip_SL(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
+
+/* Alternate Name function */
+void cd9660_rrip_NM(cd9660node *);
+void cd9660_rrip_add_NM(cd9660node *,const char *);
+
+/* Parent and child link function */
+int cd9660_rrip_PL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+int cd9660_rrip_CL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+int cd9660_rrip_RE(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+
+int cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
+
+
+
+/*
+ * Relocation directory function. I'm not quite sure what
+ * sort of parameters are needed, but personally I don't think
+ * any parameters are needed except for the memory address where
+ * the information needs to be put in
+ */
+int cd9660node_rrip_re(void *, fsnode *);
+
+/*
+ * Don't know if this function is needed because it apparently is an
+ * optional feature that does not really need to be implemented but I
+ * thought I should add it anyway.
+ */
+int cd9660_susp_ce (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+int cd9660_susp_pd (struct ISO_SUSP_ATTRIBUTES *, int);
+int cd9660_susp_sp (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+int cd9660_susp_st (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
+
+struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ER(cd9660node *, u_char, const char *,
+ const char *, const char *);
+struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES*,
+ cd9660node *);
+
+
+/* Helper functions */
+
+/* Common SUSP/RRIP functions */
+int cd9660_susp_initialize(cd9660node *, cd9660node *, cd9660node *);
+int cd9660_susp_initialize_node(cd9660node *);
+struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_create_node(int, int, const char *,
+ int);
+struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_add_entry(cd9660node *,
+ struct ISO_SUSP_ATTRIBUTES *, struct ISO_SUSP_ATTRIBUTES *, int);
+
+/* RRIP specific functions */
+int cd9660_rrip_initialize_node(cd9660node *, cd9660node *, cd9660node *);
+void cd9660_createSL(cd9660node *);
+
+/* Functions that probably can be removed */
+/* int cd9660node_initialize_node(int, char *); */
+
+
+#endif
diff --git a/usr.sbin/makefs/compat/Makefile.inc b/usr.sbin/makefs/compat/Makefile.inc
new file mode 100644
index 0000000..5fdffa1
--- /dev/null
+++ b/usr.sbin/makefs/compat/Makefile.inc
@@ -0,0 +1,8 @@
+# $FreeBSD$
+#
+
+.PATH: ${.CURDIR}/compat
+
+CFLAGS+= -I${.CURDIR}/compat
+
+SRCS+= pwcache.c strsuftoll.c
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
index ece8c65..4f3fded 100644
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs.c,v 1.30 2004/06/24 22:30:13 lukem Exp $ */
+/* $NetBSD: ffs.c,v 1.44 2009/04/28 22:49:26 joerg Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -76,17 +76,24 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "makefs.h"
+#include "ffs.h"
+
+#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
+#include <sys/statvfs.h>
+#endif
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
+
#include "ffs/ufs_bswap.h"
#include "ffs/ufs_inode.h"
#include "ffs/newfs_extern.h"
@@ -94,7 +101,7 @@ __FBSDID("$FreeBSD$");
#undef DIP
#define DIP(dp, field) \
- ((fsopts->version == 1) ? \
+ ((ffs_opts->version == 1) ? \
(dp)->ffs1_din.di_##field : (dp)->ffs2_din.di_##field)
/*
@@ -139,39 +146,71 @@ int sectorsize; /* XXX: for buf.c::getblk() */
/* publically visible functions */
+void
+ffs_prep_opts(fsinfo_t *fsopts)
+{
+ ffs_opt_t *ffs_opts;
+
+ if ((ffs_opts = calloc(1, sizeof(ffs_opt_t))) == NULL)
+ err(1, "Allocating memory for ffs_options");
+
+ fsopts->fs_specific = ffs_opts;
+
+ ffs_opts->bsize= -1;
+ ffs_opts->fsize= -1;
+ ffs_opts->cpg= -1;
+ ffs_opts->density= -1;
+ ffs_opts->minfree= -1;
+ ffs_opts->optimization= -1;
+ ffs_opts->maxcontig= -1;
+ ffs_opts->maxbpg= -1;
+ ffs_opts->avgfilesize= -1;
+ ffs_opts->avgfpdir= -1;
+ ffs_opts->version = 1;
+}
+
+void
+ffs_cleanup_opts(fsinfo_t *fsopts)
+{
+ if (fsopts->fs_specific)
+ free(fsopts->fs_specific);
+}
+
int
ffs_parse_opts(const char *option, fsinfo_t *fsopts)
{
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
+
option_t ffs_options[] = {
- { "bsize", &fsopts->bsize, 1, INT_MAX,
+ { "bsize", &ffs_opts->bsize, 1, INT_MAX,
"block size" },
- { "fsize", &fsopts->fsize, 1, INT_MAX,
+ { "fsize", &ffs_opts->fsize, 1, INT_MAX,
"fragment size" },
- { "density", &fsopts->density, 1, INT_MAX,
+ { "density", &ffs_opts->density, 1, INT_MAX,
"bytes per inode" },
- { "minfree", &fsopts->minfree, 0, 99,
+ { "minfree", &ffs_opts->minfree, 0, 99,
"minfree" },
- { "maxbpf", &fsopts->maxbpg, 1, INT_MAX,
+ { "maxbpf", &ffs_opts->maxbpg, 1, INT_MAX,
"max blocks per file in a cg" },
- { "avgfilesize", &fsopts->avgfilesize, 1, INT_MAX,
+ { "avgfilesize", &ffs_opts->avgfilesize,1, INT_MAX,
"expected average file size" },
- { "avgfpdir", &fsopts->avgfpdir, 1, INT_MAX,
+ { "avgfpdir", &ffs_opts->avgfpdir, 1, INT_MAX,
"expected # of files per directory" },
- { "extent", &fsopts->maxbsize, 1, INT_MAX,
+ { "extent", &ffs_opts->maxbsize, 1, INT_MAX,
"maximum # extent size" },
- { "maxbpcg", &fsopts->maxblkspercg, 1, INT_MAX,
+ { "maxbpcg", &ffs_opts->maxblkspercg,1, INT_MAX,
"max # of blocks per group" },
- { "version", &fsopts->version, 1, 2,
+ { "version", &ffs_opts->version, 1, 2,
"UFS version" },
- { NULL }
+ { .name = NULL }
};
char *var, *val;
int rv;
- (void)&ffs_options;
assert(option != NULL);
assert(fsopts != NULL);
+ assert(ffs_opts != NULL);
if (debug & DEBUG_FS_PARSE_OPTS)
printf("ffs_parse_opts: got `%s'\n", option);
@@ -188,9 +227,9 @@ ffs_parse_opts(const char *option, fsinfo_t *fsopts)
if (strcmp(var, "optimization") == 0) {
if (strcmp(val, "time") == 0) {
- fsopts->optimization = FS_OPTTIME;
+ ffs_opts->optimization = FS_OPTTIME;
} else if (strcmp(val, "space") == 0) {
- fsopts->optimization = FS_OPTSPACE;
+ ffs_opts->optimization = FS_OPTSPACE;
} else {
warnx("Invalid optimization `%s'", val);
goto leave_ffs_parse_opts;
@@ -277,11 +316,12 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
#if notyet
int32_t spc, nspf, ncyl, fssize;
#endif
- off_t size;
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
assert(dir != NULL);
assert(root != NULL);
assert(fsopts != NULL);
+ assert(ffs_opts != NULL);
if (debug & DEBUG_FS_VALIDATE) {
printf("ffs_validate: before defaults set:\n");
@@ -291,31 +331,31 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
/* set FFS defaults */
if (fsopts->sectorsize == -1)
fsopts->sectorsize = DFL_SECSIZE;
- if (fsopts->fsize == -1)
- fsopts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize);
- if (fsopts->bsize == -1)
- fsopts->bsize = MIN(DFL_BLKSIZE, 8 * fsopts->fsize);
- if (fsopts->cpg == -1)
- fsopts->cpg = DFL_CYLSPERGROUP;
+ if (ffs_opts->fsize == -1)
+ ffs_opts->fsize = MAX(DFL_FRAGSIZE, fsopts->sectorsize);
+ if (ffs_opts->bsize == -1)
+ ffs_opts->bsize = MIN(DFL_BLKSIZE, 8 * ffs_opts->fsize);
+ if (ffs_opts->cpg == -1)
+ ffs_opts->cpg = DFL_CYLSPERGROUP;
else
- fsopts->cpgflg = 1;
+ ffs_opts->cpgflg = 1;
/* fsopts->density is set below */
- if (fsopts->nsectors == -1)
- fsopts->nsectors = DFL_NSECTORS;
- if (fsopts->minfree == -1)
- fsopts->minfree = MINFREE;
- if (fsopts->optimization == -1)
- fsopts->optimization = DEFAULTOPT;
- if (fsopts->maxcontig == -1)
- fsopts->maxcontig =
- MAX(1, MIN(MAXPHYS, FFS_MAXBSIZE) / fsopts->bsize);
+ if (ffs_opts->nsectors == -1)
+ ffs_opts->nsectors = DFL_NSECTORS;
+ if (ffs_opts->minfree == -1)
+ ffs_opts->minfree = MINFREE;
+ if (ffs_opts->optimization == -1)
+ ffs_opts->optimization = DEFAULTOPT;
+ if (ffs_opts->maxcontig == -1)
+ ffs_opts->maxcontig =
+ MAX(1, MIN(MAXPHYS, FFS_MAXBSIZE) / ffs_opts->bsize);
/* XXX ondisk32 */
- if (fsopts->maxbpg == -1)
- fsopts->maxbpg = fsopts->bsize / sizeof(int32_t);
- if (fsopts->avgfilesize == -1)
- fsopts->avgfilesize = AVFILESIZ;
- if (fsopts->avgfpdir == -1)
- fsopts->avgfpdir = AFPDIR;
+ if (ffs_opts->maxbpg == -1)
+ ffs_opts->maxbpg = ffs_opts->bsize / sizeof(int32_t);
+ if (ffs_opts->avgfilesize == -1)
+ ffs_opts->avgfilesize = AVFILESIZ;
+ if (ffs_opts->avgfpdir == -1)
+ ffs_opts->avgfpdir = AFPDIR;
/* calculate size of tree */
ffs_size_dir(root, fsopts);
@@ -343,17 +383,19 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
*/
fsopts->size += (SBLOCK_UFS1 + SBLOCKSIZE) * ncg;
/* add space needed to store inodes, x3 for blockmaps, etc */
- if (fsopts->version == 1)
+ if (ffs_opts->version == 1)
fsopts->size += ncg * DINODE1_SIZE *
- roundup(fsopts->inodes / ncg, fsopts->bsize / DINODE1_SIZE);
+ roundup(fsopts->inodes / ncg,
+ ffs_opts->bsize / DINODE1_SIZE);
else
fsopts->size += ncg * DINODE2_SIZE *
- roundup(fsopts->inodes / ncg, fsopts->bsize / DINODE2_SIZE);
+ roundup(fsopts->inodes / ncg,
+ ffs_opts->bsize / DINODE2_SIZE);
/* add minfree */
- if (fsopts->minfree > 0)
+ if (ffs_opts->minfree > 0)
fsopts->size =
- fsopts->size * (100 + fsopts->minfree) / 100;
+ fsopts->size * (100 + ffs_opts->minfree) / 100;
/*
* XXX any other fs slop to add, such as csum's, bitmaps, etc ??
*/
@@ -362,24 +404,11 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
fsopts->size = fsopts->minsize;
/* round up to the next block */
- size = roundup(fsopts->size, fsopts->bsize);
-
- /* now check calculated sizes vs requested sizes */
- if (fsopts->maxsize > 0 && size > fsopts->maxsize) {
- if (debug & DEBUG_FS_VALIDATE) {
- printf("%s: `%s' size of %lld is larger than the "
- "maxsize of %lld; rounding down to %lld.",
- __func__, dir, (long long)size,
- (long long)fsopts->maxsize,
- (long long) rounddown(fsopts->size, fsopts->bsize));
- }
- size = rounddown(fsopts->size, fsopts->bsize);
- }
- fsopts->size = size;
+ fsopts->size = roundup(fsopts->size, ffs_opts->bsize);
/* calculate density if necessary */
- if (fsopts->density == -1)
- fsopts->density = fsopts->size / fsopts->inodes + 1;
+ if (ffs_opts->density == -1)
+ ffs_opts->density = fsopts->size / fsopts->inodes + 1;
if (debug & DEBUG_FS_VALIDATE) {
printf("ffs_validate: after defaults set:\n");
@@ -388,6 +417,12 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
dir, (long long)fsopts->size, (long long)fsopts->inodes);
}
sectorsize = fsopts->sectorsize; /* XXX - see earlier */
+
+ /* now check calculated sizes vs requested sizes */
+ if (fsopts->maxsize > 0 && fsopts->size > fsopts->maxsize) {
+ errx(1, "`%s' size of %lld is larger than the maxsize of %lld.",
+ dir, (long long)fsopts->size, (long long)fsopts->maxsize);
+ }
}
@@ -395,6 +430,8 @@ static void
ffs_dump_fsinfo(fsinfo_t *f)
{
+ ffs_opt_t *fs = f->fs_specific;
+
printf("fsopts at %p\n", f);
printf("\tsize %lld, inodes %lld, curinode %u\n",
@@ -409,20 +446,20 @@ ffs_dump_fsinfo(fsinfo_t *f)
printf("\tneedswap %d, sectorsize %d\n", f->needswap, f->sectorsize);
printf("\tbsize %d, fsize %d, cpg %d, density %d\n",
- f->bsize, f->fsize, f->cpg, f->density);
+ fs->bsize, fs->fsize, fs->cpg, fs->density);
printf("\tnsectors %d, rpm %d, minfree %d\n",
- f->nsectors, f->rpm, f->minfree);
+ fs->nsectors, fs->rpm, fs->minfree);
printf("\tmaxcontig %d, maxbpg %d\n",
- f->maxcontig, f->maxbpg);
+ fs->maxcontig, fs->maxbpg);
printf("\toptimization %s\n",
- f->optimization == FS_OPTSPACE ? "space" : "time");
+ fs->optimization == FS_OPTSPACE ? "space" : "time");
}
static int
ffs_create_image(const char *image, fsinfo_t *fsopts)
{
-#if HAVE_STRUCT_STATVFS_F_IOSIZE
+#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
struct statvfs sfs;
#endif
struct fs *fs;
@@ -434,18 +471,18 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
assert (fsopts != NULL);
/* create image */
- if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0777))
+ if ((fsopts->fd = open(image, O_RDWR | O_CREAT | O_TRUNC, 0666))
== -1) {
warn("Can't open `%s' for writing", image);
return (-1);
}
/* zero image */
-#if HAVE_STRUCT_STATVFS_F_IOSIZE
+#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
if (fstatvfs(fsopts->fd, &sfs) == -1) {
#endif
bufsize = 8192;
-#if HAVE_STRUCT_STATVFS_F_IOSIZE
+#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
warn("can't fstatvfs `%s', using default %d byte chunk",
image, bufsize);
} else
@@ -465,10 +502,12 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
if (i == -1) {
warn("zeroing image, %lld bytes to go",
(long long)bufrem);
+ free(buf);
return (-1);
}
bufrem -= i;
}
+ free(buf);
/* make the file system */
if (debug & DEBUG_FS_CREATE_IMAGE)
@@ -492,7 +531,7 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
warnx(
"Image file `%s' has %lld free inodes; %lld are required.",
image,
- (long long)fs->fs_cstotal.cs_nifree + ROOTINO,
+ (long long)(fs->fs_cstotal.cs_nifree + ROOTINO),
(long long)fsopts->inodes);
return (-1);
}
@@ -506,9 +545,11 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
struct direct tmpdir;
fsnode * node;
int curdirsize, this;
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
/* node may be NULL (empty directory) */
assert(fsopts != NULL);
+ assert(ffs_opts != NULL);
if (debug & DEBUG_FS_SIZE_DIR)
printf("ffs_size_dir: entry: bytes %lld inodes %lld\n",
@@ -516,7 +557,7 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
#define ADDDIRENT(e) do { \
tmpdir.d_namlen = strlen((e)); \
- this = DIRSIZ_SWAP(0, &tmpdir, 0); \
+ this = DIRSIZ_SWAP(0, &tmpdir, 0); \
if (debug & DEBUG_FS_SIZE_DIR_ADD_DIRENT) \
printf("ADDDIRENT: was: %s (%d) this %d cur %d\n", \
e, tmpdir.d_namlen, this, curdirsize); \
@@ -533,14 +574,12 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
* by indirect blocks, etc.
*/
#define ADDSIZE(x) do { \
- fsopts->size += roundup((x), fsopts->fsize); \
+ fsopts->size += roundup((x), ffs_opts->fsize); \
} while (0);
curdirsize = 0;
for (node = root; node != NULL; node = node->next) {
ADDDIRENT(node->name);
- if (FSNODE_EXCLUDE_P(fsopts, node))
- continue;
if (node == root) { /* we're at "." */
assert(strcmp(node->name, ".") == 0);
ADDDIRENT("..");
@@ -558,7 +597,7 @@ ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
int slen;
slen = strlen(node->symlink) + 1;
- if (slen >= (fsopts->version == 1 ?
+ if (slen >= (ffs_opts->version == 1 ?
MAXSYMLINKLEN_UFS1 :
MAXSYMLINKLEN_UFS2))
ADDSIZE(slen);
@@ -682,10 +721,12 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
union dinode din;
void *membuf;
char path[MAXPATHLEN + 1];
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
assert(dir != NULL);
assert(root != NULL);
assert(fsopts != NULL);
+ assert(ffs_opts != NULL);
(void)memset(&dirbuf, 0, sizeof(dirbuf));
@@ -696,8 +737,6 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
* pass 1: allocate inode numbers, build directory `file'
*/
for (cur = root; cur != NULL; cur = cur->next) {
- if (FSNODE_EXCLUDE_P(fsopts, cur))
- continue;
if ((cur->inode->flags & FI_ALLOCATED) == 0) {
cur->inode->flags |= FI_ALLOCATED;
if (cur == root && cur->parent != NULL)
@@ -732,8 +771,6 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
if (debug & DEBUG_FS_POPULATE)
printf("ffs_populate_dir: PASS 2 dir %s\n", dir);
for (cur = root; cur != NULL; cur = cur->next) {
- if (FSNODE_EXCLUDE_P(fsopts, cur))
- continue;
if (cur->inode->flags & FI_WRITTEN)
continue; /* skip hard-linked entries */
cur->inode->flags |= FI_WRITTEN;
@@ -746,7 +783,7 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
continue; /* child creates own inode */
/* build on-disk inode */
- if (fsopts->version == 1)
+ if (ffs_opts->version == 1)
membuf = ffs_build_dinode1(&din.ffs1_din, &dirbuf, cur,
root, fsopts);
else
@@ -777,8 +814,6 @@ ffs_populate_dir(const char *dir, fsnode *root, fsinfo_t *fsopts)
if (debug & DEBUG_FS_POPULATE)
printf("ffs_populate_dir: PASS 3 dir %s\n", dir);
for (cur = root; cur != NULL; cur = cur->next) {
- if (FSNODE_EXCLUDE_P(fsopts, cur))
- continue;
if (cur->child == NULL)
continue;
if (snprintf(path, sizeof(path), "%s/%s", dir, cur->name)
@@ -804,16 +839,20 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
int isfile, ffd;
char *fbuf, *p;
off_t bufleft, chunk, offset;
+ ssize_t nread;
struct inode in;
struct buf * bp;
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
assert (din != NULL);
assert (buf != NULL);
assert (fsopts != NULL);
+ assert (ffs_opts != NULL);
isfile = S_ISREG(DIP(din, mode));
fbuf = NULL;
ffd = -1;
+ p = NULL;
in.i_fs = (struct fs *)fsopts->superblock;
@@ -830,7 +869,7 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
in.i_number = ino;
in.i_size = DIP(din, size);
- if (fsopts->version == 1)
+ if (ffs_opts->version == 1)
memcpy(&in.i_din.ffs1_din, &din->ffs1_din,
sizeof(in.i_din.ffs1_din));
else
@@ -842,7 +881,7 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
goto write_inode_and_leave; /* mmm, cheating */
if (isfile) {
- if ((fbuf = malloc(fsopts->bsize)) == NULL)
+ if ((fbuf = malloc(ffs_opts->bsize)) == NULL)
err(1, "Allocating memory for write buffer");
if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) {
warn("Can't open `%s' for reading", (char *)buf);
@@ -854,13 +893,20 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
chunk = 0;
for (bufleft = DIP(din, size); bufleft > 0; bufleft -= chunk) {
- chunk = MIN(bufleft, fsopts->bsize);
- if (isfile) {
- if (read(ffd, fbuf, chunk) != chunk)
- err(1, "Reading `%s', %lld bytes to go",
- (char *)buf, (long long)bufleft);
+ chunk = MIN(bufleft, ffs_opts->bsize);
+ if (!isfile)
+ ;
+ else if ((nread = read(ffd, fbuf, chunk)) == -1)
+ err(EXIT_FAILURE, "Reading `%s', %lld bytes to go",
+ (char *)buf, (long long)bufleft);
+ else if (nread != chunk)
+ errx(EXIT_FAILURE, "Reading `%s', %lld bytes to go, "
+ "read %zd bytes, expected %ju bytes, does "
+ "metalog size= attribute mismatch source size?",
+ (char *)buf, (long long)bufleft, nread,
+ (uintmax_t)chunk);
+ else
p = fbuf;
- }
offset = DIP(din, size) - bufleft;
if (debug & DEBUG_FS_WRITE_FILE_BLOCK)
printf(
@@ -932,7 +978,7 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
{
struct direct de, *dp;
uint16_t llen, reclen;
- char *newbuf;
+ u_char *newbuf;
assert (dbuf != NULL);
assert (name != NULL);
@@ -969,7 +1015,7 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
dbuf->size += DIRBLKSIZ;
memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
dbuf->cur = dbuf->size - DIRBLKSIZ;
- } else { /* shrink end of previous */
+ } else if (dp) { /* shrink end of previous */
dp->d_reclen = ufs_rw16(llen,needswap);
dbuf->cur += llen;
}
@@ -993,10 +1039,12 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts)
daddr_t d;
char sbbuf[FFS_MAXBSIZE];
int32_t initediblk;
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
assert (dp != NULL);
assert (ino > 0);
assert (fsopts != NULL);
+ assert (ffs_opts != NULL);
fs = (struct fs *)fsopts->superblock;
cg = ino_to_cg(fs, ino);
@@ -1041,7 +1089,7 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts)
* Initialize inode blocks on the fly for UFS2.
*/
initediblk = ufs_rw32(cgp->cg_initediblk, fsopts->needswap);
- if (fsopts->version == 2 && cgino + INOPB(fs) > initediblk &&
+ if (ffs_opts->version == 2 && cgino + INOPB(fs) > initediblk &&
initediblk < ufs_rw32(cgp->cg_niblk, fsopts->needswap)) {
memset(buf, 0, fs->fs_bsize);
dip = (struct ufs2_dinode *)buf;
@@ -1065,14 +1113,14 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts)
d = fsbtodb(fs, ino_to_fsba(fs, ino));
ffs_rdfs(d, fs->fs_bsize, buf, fsopts);
if (fsopts->needswap) {
- if (fsopts->version == 1)
+ if (ffs_opts->version == 1)
ffs_dinode1_swap(&dp->ffs1_din,
&dp1[ino_to_fsbo(fs, ino)]);
else
ffs_dinode2_swap(&dp->ffs2_din,
&dp2[ino_to_fsbo(fs, ino)]);
} else {
- if (fsopts->version == 1)
+ if (ffs_opts->version == 1)
dp1[ino_to_fsbo(fs, ino)] = dp->ffs1_din;
else
dp2[ino_to_fsbo(fs, ino)] = dp->ffs2_din;
diff --git a/usr.sbin/makefs/ffs.h b/usr.sbin/makefs/ffs.h
new file mode 100644
index 0000000..42611a4
--- /dev/null
+++ b/usr.sbin/makefs/ffs.h
@@ -0,0 +1,66 @@
+/* $NetBSD: ffs.h,v 1.1 2004/12/20 20:51:42 jmc Exp $ */
+
+/*
+ * Copyright (c) 2001-2003 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Luke Mewburn for Wasabi 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, 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 WASABI SYSTEMS, 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _FFS_H
+#define _FFS_H
+
+typedef struct {
+ int bsize; /* block size */
+ int fsize; /* fragment size */
+ int cpg; /* cylinders per group */
+ int cpgflg; /* cpg was specified by user */
+ int density; /* bytes per inode */
+ int ntracks; /* number of tracks */
+ int nsectors; /* number of sectors */
+ int rpm; /* rpm */
+ int minfree; /* free space threshold */
+ int optimization; /* optimization (space or time) */
+ int maxcontig; /* max contiguous blocks to allocate */
+ int rotdelay; /* rotational delay between blocks */
+ int maxbpg; /* maximum blocks per file in a cyl group */
+ int nrpos; /* # of distinguished rotational positions */
+ int avgfilesize; /* expected average file size */
+ int avgfpdir; /* expected # of files per directory */
+ int version; /* filesystem version (1 = FFS, 2 = UFS2) */
+ int maxbsize; /* maximum extent size */
+ int maxblkspercg; /* max # of blocks per cylinder group */
+ /* XXX: support `old' file systems ? */
+} ffs_opt_t;
+
+#endif /* _FFS_H */
diff --git a/usr.sbin/makefs/ffs/Makefile.inc b/usr.sbin/makefs/ffs/Makefile.inc
new file mode 100644
index 0000000..d681c4e
--- /dev/null
+++ b/usr.sbin/makefs/ffs/Makefile.inc
@@ -0,0 +1,9 @@
+# $FreeBSD$
+#
+
+.PATH: ${.CURDIR}/ffs ${.CURDIR}/../../sys/ufs/ffs
+
+CFLAGS+= -I${.CURDIR}/../../sys/ufs/ffs
+
+SRCS+= ffs_alloc.c ffs_balloc.c ffs_bswap.c ffs_subr.c ufs_bmap.c
+SRCS+= buf.c mkfs.c
diff --git a/usr.sbin/makefs/ffs/buf.c b/usr.sbin/makefs/ffs/buf.c
index 08fb627..06538f5 100644
--- a/usr.sbin/makefs/ffs/buf.c
+++ b/usr.sbin/makefs/ffs/buf.c
@@ -118,7 +118,7 @@ brelse(struct buf *bp)
bp->b_bcount = 0;
return;
}
-
+
TAILQ_REMOVE(&buftail, bp, b_tailq);
free(bp->b_data);
free(bp);
@@ -160,7 +160,7 @@ bcleanup(void)
* know why there's still some buffers lying around that
* aren't brelse()d
*/
-
+
if (TAILQ_EMPTY(&buftail))
return;
@@ -201,7 +201,7 @@ getblk(int fd, struct fs *fs, daddr_t blkno, int size)
if (bp == NULL) {
if ((bp = calloc(1, sizeof(struct buf))) == NULL)
err(1, "getblk: calloc");
-
+
bp->b_bufsize = 0;
bp->b_blkno = bp->b_lblkno = blkno;
bp->b_fd = fd;
diff --git a/usr.sbin/makefs/ffs/ffs_alloc.c b/usr.sbin/makefs/ffs/ffs_alloc.c
index 0fe65e6..f676a39 100644
--- a/usr.sbin/makefs/ffs/ffs_alloc.c
+++ b/usr.sbin/makefs/ffs/ffs_alloc.c
@@ -87,7 +87,7 @@ static int32_t ffs_mapsearch(struct fs *, struct cg *, daddr_t, int);
* available block is located.
*/
int
-ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
+ffs_alloc(struct inode *ip, daddr_t lbn __unused, daddr_t bpref, int size,
daddr_t *bnp)
{
struct fs *fs = ip->i_fs;
@@ -95,7 +95,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
int cg;
*bnp = 0;
- if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) {
+ if (size > fs->fs_bsize || fragoff(fs, size) != 0) {
errx(1, "ffs_alloc: bad size: bsize %d size %d",
fs->fs_bsize, size);
}
@@ -187,11 +187,7 @@ ffs_blkpref_ufs1(struct inode *ip, daddr_t lbn, int indx, int32_t *bap)
}
daddr_t
-ffs_blkpref_ufs2(ip, lbn, indx, bap)
- struct inode *ip;
- daddr_t lbn;
- int indx;
- int64_t *bap;
+ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int64_t *bap)
{
struct fs *fs;
int cg;
@@ -385,11 +381,11 @@ ffs_alloccgblk(struct inode *ip, struct buf *bp, daddr_t bpref)
int32_t bno;
struct fs *fs = ip->i_fs;
const int needswap = UFS_FSNEEDSWAP(fs);
- u_int8_t *blksfree;
+ u_int8_t *blksfree_swap;
cgp = (struct cg *)bp->b_data;
- blksfree = cg_blksfree_swap(cgp, needswap);
- if (bpref == 0 || dtog(fs, bpref) != ufs_rw32(cgp->cg_cgx, needswap)) {
+ blksfree_swap = cg_blksfree_swap(cgp, needswap);
+ if (bpref == 0 || (uint32_t)dtog(fs, bpref) != ufs_rw32(cgp->cg_cgx, needswap)) {
bpref = ufs_rw32(cgp->cg_rotor, needswap);
} else {
bpref = blknum(fs, bpref);
@@ -397,7 +393,7 @@ ffs_alloccgblk(struct inode *ip, struct buf *bp, daddr_t bpref)
/*
* if the requested block is available, use it
*/
- if (ffs_isblock(fs, blksfree, fragstoblks(fs, bno)))
+ if (ffs_isblock(fs, blksfree_swap, fragstoblks(fs, bno)))
goto gotit;
}
/*
@@ -409,7 +405,7 @@ ffs_alloccgblk(struct inode *ip, struct buf *bp, daddr_t bpref)
cgp->cg_rotor = ufs_rw32(bno, needswap);
gotit:
blkno = fragstoblks(fs, bno);
- ffs_clrblock(fs, blksfree, (long)blkno);
+ ffs_clrblock(fs, blksfree_swap, (long)blkno);
ffs_clusteracct(fs, cgp, blkno, -1);
ufs_add32(cgp->cg_cs.cs_nbfree, -1, needswap);
fs->fs_cstotal.cs_nbfree--;
@@ -436,14 +432,15 @@ ffs_blkfree(struct inode *ip, daddr_t bno, long size)
struct fs *fs = ip->i_fs;
const int needswap = UFS_FSNEEDSWAP(fs);
- if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0 ||
+ if (size > fs->fs_bsize || fragoff(fs, size) != 0 ||
fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) {
errx(1, "blkfree: bad size: bno %lld bsize %d size %ld",
(long long)bno, fs->fs_bsize, size);
}
cg = dtog(fs, bno);
if (bno >= fs->fs_size) {
- warnx("bad block %lld, ino %d", (long long)bno, ip->i_number);
+ warnx("bad block %lld, ino %llu", (long long)bno,
+ (unsigned long long)ip->i_number);
return;
}
error = bread(ip->i_fd, ip->i_fs, fsbtodb(fs, cgtod(fs, cg)),
@@ -622,7 +619,7 @@ ffs_clusteracct(struct fs *fs, struct cg *cgp, int32_t blkno, int cnt)
*/
start = blkno + 1;
end = start + fs->fs_contigsumsize;
- if (end >= ufs_rw32(cgp->cg_nclusterblks, needswap))
+ if ((unsigned)end >= ufs_rw32(cgp->cg_nclusterblks, needswap))
end = ufs_rw32(cgp->cg_nclusterblks, needswap);
mapp = &freemapp[start / NBBY];
map = *mapp++;
diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c
index ce9ec59..924ab6c 100644
--- a/usr.sbin/makefs/ffs/mkfs.c
+++ b/usr.sbin/makefs/ffs/mkfs.c
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include "makefs.h"
+#include "ffs.h"
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
@@ -61,6 +62,10 @@ __FBSDID("$FreeBSD$");
#include "ffs/ffs_extern.h"
#include "ffs/newfs_extern.h"
+#ifndef BBSIZE
+#define BBSIZE 8192 /* size of boot area, with label */
+#endif
+
static void initcg(int, time_t, const fsinfo_t *);
static int ilog2(int);
@@ -102,6 +107,7 @@ static int opt; /* optimization preference (space or time) */
static int density; /* number of bytes per inode */
static int maxcontig; /* max contiguous blocks to allocate */
static int maxbpg; /* maximum blocks per file in a cyl group */
+static int bbsize; /* boot block size */
static int sbsize; /* superblock size */
static int avgfilesize; /* expected average file size */
static int avgfpdir; /* expected number of files per directory */
@@ -115,21 +121,23 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts)
void *space;
int size, blks;
int nprintcols, printcolwidth;
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
- Oflag = fsopts->version;
+ Oflag = ffs_opts->version;
fssize = fsopts->size / fsopts->sectorsize;
sectorsize = fsopts->sectorsize;
- fsize = fsopts->fsize;
- bsize = fsopts->bsize;
- maxbsize = fsopts->maxbsize;
- maxblkspercg = fsopts->maxblkspercg;
- minfree = fsopts->minfree;
- opt = fsopts->optimization;
- density = fsopts->density;
- maxcontig = fsopts->maxcontig;
- maxbpg = fsopts->maxbpg;
- avgfilesize = fsopts->avgfilesize;
- avgfpdir = fsopts->avgfpdir;
+ fsize = ffs_opts->fsize;
+ bsize = ffs_opts->bsize;
+ maxbsize = ffs_opts->maxbsize;
+ maxblkspercg = ffs_opts->maxblkspercg;
+ minfree = ffs_opts->minfree;
+ opt = ffs_opts->optimization;
+ density = ffs_opts->density;
+ maxcontig = ffs_opts->maxcontig;
+ maxbpg = ffs_opts->maxbpg;
+ avgfilesize = ffs_opts->avgfilesize;
+ avgfpdir = ffs_opts->avgfpdir;
+ bbsize = BBSIZE;
sbsize = SBLOCKSIZE;
if (Oflag == 0) {
diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8
index e0924d5..974477c 100644
--- a/usr.sbin/makefs/makefs.8
+++ b/usr.sbin/makefs/makefs.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: makefs.8,v 1.13 2004/02/13 17:56:18 wiz Exp $
+.\" $NetBSD: makefs.8,v 1.32 2009/01/20 20:47:25 bjh21 Exp $
.\"
.\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
.\" All rights reserved.
@@ -35,7 +35,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 30, 2003
+.Dd January 10, 2009
.Dt MAKEFS 8
.Os
.Sh NAME
@@ -43,43 +43,19 @@
.Nd create a file system image from a directory tree
.Sh SYNOPSIS
.Nm
-.Bk -words
-.Op Fl t Ar fs-type
-.Ek
-.Bk -words
-.Op Fl o Ar fs-options
-.Ek
-.Bk -words
-.Op Fl d Ar debug-mask
-.Ek
-.Bk -words
+.Op Fl x
.Op Fl B Ar byte-order
-.Ek
-.Bk -words
-.Op Fl S Ar sector-size
-.Ek
-.Bk -words
-.Op Fl M Ar minimum-size
-.Ek
-.Bk -words
-.Op Fl m Ar maximum-size
-.Ek
-.Bk -words
-.Op Fl s Ar image-size
-.Ek
-.Bk -words
.Op Fl b Ar free-blocks
-.Ek
-.Bk -words
-.Op Fl f Ar free-files
-.Ek
-.Bk -words
+.Op Fl d Ar debug-mask
.Op Fl F Ar specfile
-.Ek
-.Op Fl x
-.Bk -words
+.Op Fl f Ar free-files
+.Op Fl M Ar minimum-size
+.Op Fl m Ar maximum-size
.Op Fl N Ar userdb-dir
-.Ek
+.Op Fl o Ar fs-options
+.Op Fl S Ar sector-size
+.Op Fl s Ar image-size
+.Op Fl t Ar fs-type
.Ar image-file
.Ar directory
.Sh DESCRIPTION
@@ -93,56 +69,22 @@ No special devices or privileges are required to perform this task.
.Pp
The options are as follows:
.Bl -tag -width flag
-.It Fl t Ar fs-type
-Create an
-.Ar fs-type
-file system image.
-The following file system types are supported:
-.Bl -tag -width ffs -offset indent
-.It Sy ffs
-BSD fast file system (default).
-.El
-.It Fl o Ar fs-options
-Set file system specific options.
-.Ar fs-options
-is a comma separated list of options.
-Valid file system specific options are detailed below.
-.It Fl d Ar debug-mask
-Enable various levels of debugging, depending upon which bits are set
-in
-.Ar debug-mask .
-XXX: document these
.It Fl B Ar byte-order
Set the byte order of the image to
.Ar byte-order .
Valid byte orders are
.Ql 4321 ,
-.Ql big
+.Ql big ,
or
.Ql be
for big endian, and
.Ql 1234 ,
-.Ql little
+.Ql little ,
or
.Ql le
for little endian.
Some file systems may have a fixed byte order; in those cases this
argument will be ignored.
-.It Fl S Ar sector-size
-Set the file system sector size to
-.Ar sector-size .
-Defaults to 512.
-.It Fl M Ar minimum-size
-Set the minimum size of the file system image to
-.Ar minimum-size .
-.It Fl m Ar maximum-size
-Set the maximum size of the file system image to
-.Ar maximum-size .
-An error will be raised if the target file system needs to be larger
-than this to accommodate the provided directory tree.
-.It Fl s Ar image-size
-Set the size of the file system image to
-.Ar image-size .
.It Fl b Ar free-blocks
Ensure that a minimum of
.Ar free-blocks
@@ -151,16 +93,12 @@ An optional
.Ql %
suffix may be provided to indicate that
.Ar free-blocks
-indicates a percentage of the calculated image size
-.It Fl f Ar free-files
-Ensure that a minimum of
-.Ar free-files
-free files (inodes) exist in the image.
-An optional
-.Ql %
-suffix may be provided to indicate that
-.Ar free-files
-indicates a percentage of the calculated image size
+indicates a percentage of the calculated image size.
+.It Fl d Ar debug-mask
+Enable various levels of debugging, depending upon which bits are
+set in
+.Ar debug-mask .
+XXX: document these
.It Fl F Ar specfile
Use
.Ar specfile
@@ -169,23 +107,23 @@ as an
.Sq specfile
specification.
.Pp
-If a specfile entry exists in the underlying file system, its permissions and
-modification time will be used unless specifically overridden by the specfile.
-An error will be raised if the type of entry in the specfile conflicts
-with that of an existing entry.
+If a specfile entry exists in the underlying file system, its
+permissions and modification time will be used unless specifically
+overridden by the specfile.
+An error will be raised if the type of entry in the specfile
+conflicts with that of an existing entry.
.Pp
-In the opposite case
-(where a specfile entry does not have an entry in the underlying file system)
-the following occurs:
+In the opposite case (where a specfile entry does not have an entry
+in the underlying file system) the following occurs:
If the specfile entry is marked
.Sy optional ,
the specfile entry is ignored.
-Otherwise, the entry will be created in the image,
-and it is necessary to specify at least the following parameters
-in the specfile:
+Otherwise, the entry will be created in the image, and it is
+necessary to specify at least the following parameters in the
+specfile:
.Sy type ,
.Sy mode ,
-.Sy gname
+.Sy gname ,
or
.Sy gid ,
and
@@ -203,8 +141,23 @@ If
.Sy flags
isn't provided, the current file flags will be used.
Missing regular file entries will be created as zero-length files.
-.It Fl x
-Exclude file system nodes not explicitly listed in the specfile.
+.It Fl f Ar free-files
+Ensure that a minimum of
+.Ar free-files
+free files (inodes) exist in the image.
+An optional
+.Ql %
+suffix may be provided to indicate that
+.Ar free-files
+indicates a percentage of the calculated image size.
+.It Fl M Ar minimum-size
+Set the minimum size of the file system image to
+.Ar minimum-size .
+.It Fl m Ar maximum-size
+Set the maximum size of the file system image to
+.Ar maximum-size .
+An error will be raised if the target file system needs to be larger
+than this to accommodate the provided directory tree.
.It Fl N Ar dbdir
Use the user database text file
.Pa master.passwd
@@ -217,6 +170,32 @@ rather than using the results from the system's
and
.Xr getgrnam 3
(and related) library calls.
+.It Fl o Ar fs-options
+Set file system specific options.
+.Ar fs-options
+is a comma separated list of options.
+Valid file system specific options are detailed below.
+.It Fl S Ar sector-size
+Set the file system sector size to
+.Ar sector-size .
+.\" XXX: next line also true for cd9660?
+Defaults to 512.
+.It Fl s Ar image-size
+Set the size of the file system image to
+.Ar image-size .
+.It Fl t Ar fs-type
+Create an
+.Ar fs-type
+file system image.
+The following file system types are supported:
+.Bl -tag -width cd9660 -offset indent
+.It Sy ffs
+BSD fast file system (default).
+.It Sy cd9660
+ISO 9660 file system.
+.El
+.It Fl x
+Exclude file system nodes not explicitly listed in the specfile.
.El
.Pp
Where sizes are specified, a decimal number of bytes is expected.
@@ -228,13 +207,13 @@ Each number may have one of the following optional suffixes:
.It b
Block; multiply by 512
.It k
-Kilo; multiply by 1024 (1 KB)
+Kibi; multiply by 1024 (1 KiB)
.It m
-Mega; multiply by 1048576 (1 MB)
+Mebi; multiply by 1048576 (1 MiB)
.It g
-Giga; multiply by 1073741824 (1 GB)
+Gibi; multiply by 1073741824 (1 GiB)
.It t
-Tera; multiply by 1099511627776 (1 TB)
+Tebi; multiply by 1099511627776 (1 TiB)
.It w
Word; multiply by the number of bytes in an integer
.El
@@ -243,37 +222,109 @@ Word; multiply by the number of bytes in an integer
.Ss FFS-specific options
.Sy ffs
images have ffs-specific optional parameters that may be provided.
-Each of the options consists of a keyword, an equals sign
+Each of the options consists of a keyword, an equal sign
.Pq Ql = ,
and a value.
The following keywords are supported:
.Pp
.Bl -tag -width optimization -offset indent -compact
.It Sy avgfilesize
-Expected average file size
+Expected average file size.
.It Sy avgfpdir
-Expected number of files per directory
+Expected number of files per directory.
.It Sy bsize
-Block size
+Block size.
.It Sy density
-Bytes per inode
+Bytes per inode.
.It Sy fsize
-Fragment size
+Fragment size.
.It Sy maxbpg
-Maximum blocks per file in a cylinder group
+Maximum blocks per file in a cylinder group.
.It Sy minfree
-Minimum % free
+Minimum % free.
.It Sy optimization
Optimization preference; one of
.Ql space
or
.Ql time .
.It Sy extent
-Maximum extent size
+Maximum extent size.
.It Sy maxbpcg
-Maximum total number of blocks in a cylinder group
+Maximum total number of blocks in a cylinder group.
.It Sy version
-UFS version. 1 for FFS (default), 2 for UFS2
+UFS version.
+1 for FFS (default), 2 for UFS2.
+.El
+.Ss CD9660-specific options
+.Sy cd9660
+images have ISO9660-specific optional parameters that may be
+provided.
+The arguments consist of a keyword and, optionally, an equal sign
+.Pq Ql = ,
+and a value.
+The following keywords are supported:
+.Pp
+.Bl -tag -width omit-trailing-period -offset indent -compact
+.It Sy allow-deep-trees
+Allow the directory structure to exceed the maximum specified in
+the spec.
+.\" .It Sy allow-illegal-chars
+.\" Unknown
+.\" .It Sy allow-lowercase
+.\" Unknown
+.It Sy allow-max-name
+Allow 37 instead of 33 characters for filenames by omitting the
+version id.
+.It Sy allow-multidot
+Allow multiple dots in a filename.
+.It Sy applicationid
+Application ID of the image.
+.It Sy archimedes
+Use the
+.Ql ARCHIMEDES
+extension to encode
+.Tn RISC OS
+metadata.
+.It Sy boot-load-segment
+Set load segment for the boot image.
+.It Sy bootimage
+Filename of a boot image in the format
+.Dq sysid;filename ,
+where
+.Dq sysid
+is one of
+.Ql i386 ,
+.Ql mac68k ,
+.Ql macppc ,
+or
+.Ql powerpc .
+.It Sy generic-bootimage
+Load a generic boot image into the first 32K of the cd9660 image.
+.It Sy hard-disk-boot
+Boot image is a hard disk image.
+.It Sy keep-bad-images
+Don't throw away images whose write was aborted due to an error.
+For debugging purposes.
+.It Sy label
+Label name of the image.
+.It Sy no-boot
+Boot image is not bootable.
+.It Sy no-emul-boot
+Boot image is a
+.Dq no emulation
+ElTorito image.
+.It Sy no-trailing-padding
+Do not pad the image (apparently Linux needs the padding).
+.\" .It Sy omit-trailing-period
+.\" Unknown
+.It Sy preparer
+Preparer ID of the image.
+.It Sy publisher
+Publisher ID of the image.
+.It Sy rockridge
+Use RockRidge extensions (for longer filenames, etc.).
+.It Sy volumeid
+Volume set identifier of the image.
.El
.Sh SEE ALSO
.Xr mtree 8 ,
@@ -285,4 +336,11 @@ utility appeared in
.Nx 1.6 .
.Sh AUTHORS
.An Luke Mewburn
-.Aq lukem@NetBSD.org .
+.Aq lukem@NetBSD.org
+(original program)
+.An Daniel Watt ,
+.An Walter Deignan ,
+.An Ryan Gabrys ,
+.An Alan Perez-Rathke ,
+.An Ram Vedam
+(cd9660 support)
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index c3e4bd2..f2420b6 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.c,v 1.20 2004/06/20 22:20:18 jmc Exp $ */
+/* $NetBSD: makefs.c,v 1.26 2006/10/22 21:11:56 christos Exp $ */
/*
* Copyright (c) 2001-2003 Wasabi Systems, Inc.
@@ -55,14 +55,18 @@ __FBSDID("$FreeBSD$");
*/
typedef struct {
const char *type;
+ void (*prepare_options)(fsinfo_t *);
int (*parse_options)(const char *, fsinfo_t *);
+ void (*cleanup_options)(fsinfo_t *);
void (*make_fs)(const char *, const char *, fsnode *,
fsinfo_t *);
} fstype_t;
static fstype_t fstypes[] = {
- { "ffs", ffs_parse_opts, ffs_makefs },
- { NULL },
+ { "ffs", ffs_prep_opts, ffs_parse_opts, ffs_cleanup_opts, ffs_makefs },
+ { "cd9660", cd9660_prep_opts, cd9660_parse_opts, cd9660_cleanup_opts,
+ cd9660_makefs},
+ { .type = NULL },
};
u_int debug;
@@ -92,17 +96,9 @@ main(int argc, char *argv[])
(void)memset(&fsoptions, 0, sizeof(fsoptions));
fsoptions.fd = -1;
fsoptions.sectorsize = -1;
- fsoptions.bsize= -1;
- fsoptions.fsize= -1;
- fsoptions.cpg= -1;
- fsoptions.density= -1;
- fsoptions.minfree= -1;
- fsoptions.optimization= -1;
- fsoptions.maxcontig= -1;
- fsoptions.maxbpg= -1;
- fsoptions.avgfilesize= -1;
- fsoptions.avgfpdir= -1;
- fsoptions.version = 1;
+
+ if (fstype->prepare_options)
+ fstype->prepare_options(&fsoptions);
specfile = NULL;
if (gettimeofday(&start, NULL) == -1)
@@ -148,8 +144,7 @@ main(int argc, char *argv[])
break;
case 'd':
- debug =
- (int)strsuftoll("debug mask", optarg, 0, UINT_MAX);
+ debug = strtoll(optarg, NULL, 0);
break;
case 'f':
@@ -212,8 +207,13 @@ main(int argc, char *argv[])
break;
case 't':
+ /* Check current one and cleanup if necessary. */
+ if (fstype->cleanup_options)
+ fstype->cleanup_options(&fsoptions);
+ fsoptions.fs_specific = NULL;
if ((fstype = get_fstype(optarg)) == NULL)
errx(1, "Unknown fs type `%s'.", optarg);
+ fstype->prepare_options(&fsoptions);
break;
case 'x':
@@ -250,7 +250,7 @@ main(int argc, char *argv[])
if (specfile) { /* apply a specfile */
TIMER_START(start);
- apply_specfile(specfile, argv[1], root);
+ apply_specfile(specfile, argv[1], root, fsoptions.onlyspec);
TIMER_RESULTS(start, "apply_specfile");
}
@@ -265,6 +265,8 @@ main(int argc, char *argv[])
fstype->make_fs(argv[0], argv[1], root, &fsoptions);
TIMER_RESULTS(start, "make_fs");
+ free_fsnodes(root);
+
exit(0);
/* NOTREACHED */
}
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index ce18bf8..997c4db 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.h,v 1.14 2004/06/20 22:20:18 jmc Exp $ */
+/* $NetBSD: makefs.h,v 1.20 2008/12/28 21:51:46 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -126,27 +126,7 @@ typedef struct {
int needswap; /* non-zero if byte swapping needed */
int sectorsize; /* sector size */
- /* ffs specific options */
- int bsize; /* block size */
- int fsize; /* fragment size */
- int cpg; /* cylinders per group */
- int cpgflg; /* cpg was specified by user */
- int density; /* bytes per inode */
- int ntracks; /* number of tracks */
- int nsectors; /* number of sectors */
- int rpm; /* rpm */
- int minfree; /* free space threshold */
- int optimization; /* optimization (space or time) */
- int maxcontig; /* max contiguous blocks to allocate */
- int rotdelay; /* rotational delay between blocks */
- int maxbpg; /* maximum blocks per file in a cyl group */
- int nrpos; /* # of distinguished rotational positions */
- int avgfilesize; /* expected average file size */
- int avgfpdir; /* expected # of files per directory */
- int version; /* filesystem version (1 = FFS, 2 = UFS2) */
- int maxbsize; /* maximum extent size */
- int maxblkspercg; /* max # of blocks per cylinder group */
- /* XXX: support `old' file systems ? */
+ void *fs_specific; /* File system specific additions. */
} fsinfo_t;
@@ -164,15 +144,22 @@ typedef struct {
} option_t;
-void apply_specfile(const char *, const char *, fsnode *);
+void apply_specfile(const char *, const char *, fsnode *, int);
void dump_fsnodes(const char *, fsnode *);
const char * inode_type(mode_t);
int set_option(option_t *, const char *, const char *);
fsnode * walk_dir(const char *, fsnode *);
+void free_fsnodes(fsnode *);
+void ffs_prep_opts(fsinfo_t *);
int ffs_parse_opts(const char *, fsinfo_t *);
+void ffs_cleanup_opts(fsinfo_t *);
void ffs_makefs(const char *, const char *, fsnode *, fsinfo_t *);
+void cd9660_prep_opts(fsinfo_t *);
+int cd9660_parse_opts(const char *, fsinfo_t *);
+void cd9660_cleanup_opts(fsinfo_t *);
+void cd9660_makefs(const char *, const char *, fsnode *, fsinfo_t *);
extern u_int debug;
@@ -211,6 +198,7 @@ extern struct timespec start_time;
#define DEBUG_BUF_GETBLK 0x02000000
#define DEBUG_APPLY_SPECFILE 0x04000000
#define DEBUG_APPLY_SPECENTRY 0x08000000
+#define DEBUG_APPLY_SPECONLY 0x10000000
#define TIMER_START(x) \
@@ -222,8 +210,9 @@ extern struct timespec start_time;
struct timeval end, td; \
gettimeofday(&end, NULL); \
timersub(&end, &(x), &td); \
- printf("%s took %ld.%06ld seconds\n", \
- (d), (long) td.tv_sec, (long) td.tv_usec); \
+ printf("%s took %lld.%06ld seconds\n", \
+ (d), (long long)td.tv_sec, \
+ (long)td.tv_usec); \
}
@@ -249,56 +238,56 @@ extern struct timespec start_time;
* File system internal flags, also in fs_flags.
* (Pick highest number to avoid conflicts with others)
*/
-#define FS_SWAPPED 0x80000000 /* file system is endian swapped */
-#define FS_INTERNAL 0x80000000 /* mask for internal flags */
+#define FS_SWAPPED 0x80000000 /* file system is endian swapped */
+#define FS_INTERNAL 0x80000000 /* mask for internal flags */
-#define FS_ISCLEAN 1
+#define FS_ISCLEAN 1
-#define DINODE1_SIZE (sizeof(struct ufs1_dinode))
-#define DINODE2_SIZE (sizeof(struct ufs2_dinode))
+#define DINODE1_SIZE (sizeof(struct ufs1_dinode))
+#define DINODE2_SIZE (sizeof(struct ufs2_dinode))
-#define MAXSYMLINKLEN_UFS1 ((NDADDR + NIADDR) * sizeof(ufs1_daddr_t))
-#define MAXSYMLINKLEN_UFS2 ((NDADDR + NIADDR) * sizeof(ufs2_daddr_t))
+#define MAXSYMLINKLEN_UFS1 ((NDADDR + NIADDR) * sizeof(ufs1_daddr_t))
+#define MAXSYMLINKLEN_UFS2 ((NDADDR + NIADDR) * sizeof(ufs2_daddr_t))
#if (BYTE_ORDER == LITTLE_ENDIAN)
-#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
- (((oldfmt) && !(needswap)) ? \
+#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
+ (((oldfmt) && !(needswap)) ? \
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
#else
-#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
- (((oldfmt) && (needswap)) ? \
+#define DIRSIZ_SWAP(oldfmt, dp, needswap) \
+ (((oldfmt) && (needswap)) ? \
DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
#endif
-#define cg_chkmagic_swap(cgp, ns) \
+#define cg_chkmagic_swap(cgp, ns) \
(ufs_rw32((cgp)->cg_magic, (ns)) == CG_MAGIC)
-#define cg_inosused_swap(cgp, ns) \
+#define cg_inosused_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_iusedoff, (ns))))
-#define cg_blksfree_swap(cgp, ns) \
+#define cg_blksfree_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_freeoff, (ns))))
-#define cg_clustersfree_swap(cgp, ns) \
+#define cg_clustersfree_swap(cgp, ns) \
((u_int8_t *)((u_int8_t *)(cgp) + ufs_rw32((cgp)->cg_clusteroff, (ns))))
-#define cg_clustersum_swap(cgp, ns) \
+#define cg_clustersum_swap(cgp, ns) \
((int32_t *)((uintptr_t)(cgp) + ufs_rw32((cgp)->cg_clustersumoff, ns)))
struct fs;
-void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
+void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
/*
* Declarations for compat routines.
*/
long long strsuftoll(const char *, const char *, long long, long long);
long long strsuftollx(const char *, const char *,
- long long, long long, char *, size_t);
+ long long, long long, char *, size_t);
struct passwd;
int uid_from_user(const char *, uid_t *);
int pwcache_userdb(int (*)(int), void (*)(void),
- struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
+ struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
struct group;
int gid_from_group(const char *, gid_t *);
int pwcache_groupdb(int (*)(int), void (*)(void),
- struct group * (*)(const char *), struct group * (*)(gid_t));
+ struct group * (*)(const char *), struct group * (*)(gid_t));
int setup_getid(const char *dir);
diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c
index e485787..0d7bd8e 100644
--- a/usr.sbin/makefs/walk.c
+++ b/usr.sbin/makefs/walk.c
@@ -1,4 +1,4 @@
-/* $NetBSD: walk.c,v 1.17 2004/06/20 22:20:18 jmc Exp $ */
+/* $NetBSD: walk.c,v 1.24 2008/12/28 21:51:46 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -35,41 +35,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- * The function link_check() was inspired from NetBSD's usr.bin/du/du.c,
- * which has the following copyright notice:
- *
- *
- * 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
- * Chris Newcomb.
- *
- * 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.
- */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -84,13 +49,13 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "makefs.h"
-
#include "mtree.h"
-#include "extern.h" /* NB: mtree */
+#include "extern.h"
-static void apply_specdir(const char *, NODE *, fsnode *);
+static void apply_specdir(const char *, NODE *, fsnode *, int);
static void apply_specentry(const char *, NODE *, fsnode *);
static fsnode *create_fsnode(const char *, struct stat *);
static fsinode *link_check(fsinode *);
@@ -164,6 +129,10 @@ walk_dir(const char *dir, fsnode *parent)
free(cur->inode);
cur->inode = curino;
cur->inode->nlink++;
+ if (debug & DEBUG_WALK_DIR_LINKCHECK)
+ printf("link_check: found [%llu, %llu]\n",
+ (unsigned long long)curino->st.st_dev,
+ (unsigned long long)curino->st.st_ino);
}
}
if (S_ISLNK(cur->type)) {
@@ -201,6 +170,53 @@ create_fsnode(const char *name, struct stat *stbuf)
}
/*
+ * free_fsnodes --
+ * Removes node from tree and frees it and all of
+ * its decendents.
+ */
+void
+free_fsnodes(fsnode *node)
+{
+ fsnode *cur, *next;
+
+ assert(node != NULL);
+
+ /* for ".", start with actual parent node */
+ if (node->first == node) {
+ assert(node->name[0] == '.' && node->name[1] == '\0');
+ if (node->parent) {
+ assert(node->parent->child == node);
+ node = node->parent;
+ }
+ }
+
+ /* Find ourselves in our sibling list and unlink */
+ if (node->first != node) {
+ for (cur = node->first; cur->next; cur = cur->next) {
+ if (cur->next == node) {
+ cur->next = node->next;
+ node->next = NULL;
+ break;
+ }
+ }
+ }
+
+ for (cur = node; cur != NULL; cur = next) {
+ next = cur->next;
+ if (cur->child) {
+ cur->child->parent = NULL;
+ free_fsnodes(cur->child);
+ }
+ if (cur->inode->nlink-- == 1)
+ free(cur->inode);
+ if (cur->symlink)
+ free(cur->symlink);
+ free(cur->name);
+ free(cur);
+ }
+}
+
+/*
* apply_specfile --
* read in the mtree(8) specfile, and apply it to the tree
* at dir,parent. parameters in parent on equivalent types
@@ -208,7 +224,7 @@ create_fsnode(const char *name, struct stat *stbuf)
* entries will be added.
*/
void
-apply_specfile(const char *specfile, const char *dir, fsnode *parent)
+apply_specfile(const char *specfile, const char *dir, fsnode *parent, int speconly)
{
struct timeval start;
FILE *fp;
@@ -236,7 +252,8 @@ apply_specfile(const char *specfile, const char *dir, fsnode *parent)
assert(root->type == F_DIR);
/* merge in the changes */
- apply_specdir(dir, root, parent);
+ apply_specdir(dir, root, parent, speconly);
+
}
static u_int
@@ -265,8 +282,9 @@ nodetoino(u_int type)
/* NOTREACHED */
}
+
static void
-apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode)
+apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly)
{
char path[MAXPATHLEN + 1];
NODE *curnode;
@@ -287,6 +305,30 @@ apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode)
apply_specentry(dir, specnode, dirnode);
+ /* Remove any filesystem nodes not found in specfile */
+ /* XXX inefficient. This is O^2 in each dir and it would
+ * have been better never to have walked this part of the tree
+ * to begin with
+ */
+ if (speconly) {
+ fsnode *next;
+ assert(dirnode->name[0] == '.' && dirnode->name[1] == '\0');
+ for (curfsnode = dirnode->next; curfsnode != NULL; curfsnode = next) {
+ next = curfsnode->next;
+ for (curnode = specnode->child; curnode != NULL;
+ curnode = curnode->next) {
+ if (strcmp(curnode->name, curfsnode->name) == 0)
+ break;
+ }
+ if (curnode == NULL) {
+ if (debug & DEBUG_APPLY_SPECONLY) {
+ printf("apply_specdir: trimming %s/%s %p\n", dir, curfsnode->name, curfsnode);
+ }
+ free_fsnodes(curfsnode);
+ }
+ }
+ }
+
/* now walk specnode->child matching up with dirnode */
for (curnode = specnode->child; curnode != NULL;
curnode = curnode->next) {
@@ -328,6 +370,9 @@ apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode)
curnode->flags & F_GNAME, "group");
NODETEST(curnode->flags & F_UID ||
curnode->flags & F_UNAME, "user");
+/* if (curnode->type == F_BLOCK || curnode->type == F_CHAR)
+ NODETEST(curnode->flags & F_DEV,
+ "device number");*/
#undef NODETEST
if (debug & DEBUG_APPLY_SPECFILE)
@@ -367,7 +412,7 @@ apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode)
if (curfsnode->type != S_IFDIR)
errx(1, "`%s' is not a directory", path);
assert (curfsnode->child != NULL);
- apply_specdir(path, curnode, curfsnode->child);
+ apply_specdir(path, curnode, curfsnode->child, speconly);
}
}
}
@@ -444,6 +489,12 @@ apply_specentry(const char *dir, NODE *specnode, fsnode *dirnode)
dirnode->inode->st.st_flags = specnode->st_flags;
}
#endif
+/* if (specnode->flags & F_DEV) {
+ ASEPRINT("rdev", "%#llx",
+ (unsigned long long)dirnode->inode->st.st_rdev,
+ (unsigned long long)specnode->st_rdev);
+ dirnode->inode->st.st_rdev = specnode->st_rdev;
+ }*/
#undef ASEPRINT
dirnode->flags |= FSNODE_F_HASSPEC;
@@ -493,11 +544,11 @@ dump_fsnodes(const char *dir, fsnode *root)
/*
* inode_type --
* for a given inode type `mode', return a descriptive string.
+ * for most cases, uses inotype() from mtree/misc.c
*/
const char *
inode_type(mode_t mode)
{
-
if (S_ISREG(mode))
return ("file");
if (S_ISLNK(mode))
@@ -521,48 +572,78 @@ inode_type(mode_t mode)
/*
* link_check --
- * return pointer to fsnode matching `entry's st_ino & st_dev if it exists,
+ * return pointer to fsinode matching `entry's st_ino & st_dev if it exists,
* otherwise add `entry' to table and return NULL
*/
+/* This was borrowed from du.c and tweaked to keep an fsnode
+ * pointer instead. -- dbj@netbsd.org
+ */
static fsinode *
link_check(fsinode *entry)
{
- static struct dupnode {
- uint32_t dev;
- uint64_t ino;
- fsinode *dup;
- } *dups, *newdups;
- static int ndups, maxdups;
-
- int i;
-
- assert (entry != NULL);
-
- /* XXX; maybe traverse in reverse for speed? */
- for (i = 0; i < ndups; i++) {
- if (dups[i].dev == entry->st.st_dev &&
- dups[i].ino == entry->st.st_ino) {
- if (debug & DEBUG_WALK_DIR_LINKCHECK)
- printf("link_check: found [%d,%d]\n",
- entry->st.st_dev, entry->st.st_ino);
- return (dups[i].dup);
+ static struct entry {
+ fsinode *data;
+ } *htable;
+ static int htshift; /* log(allocated size) */
+ static int htmask; /* allocated size - 1 */
+ static int htused; /* 2*number of insertions */
+ int h, h2;
+ uint64_t tmp;
+ /* this constant is (1<<64)/((1+sqrt(5))/2)
+ * aka (word size)/(golden ratio)
+ */
+ const uint64_t HTCONST = 11400714819323198485ULL;
+ const int HTBITS = 64;
+
+ /* Never store zero in hashtable */
+ assert(entry);
+
+ /* Extend hash table if necessary, keep load under 0.5 */
+ if (htused<<1 >= htmask) {
+ struct entry *ohtable;
+
+ if (!htable)
+ htshift = 10; /* starting hashtable size */
+ else
+ htshift++; /* exponential hashtable growth */
+
+ htmask = (1 << htshift) - 1;
+ htused = 0;
+
+ ohtable = htable;
+ htable = calloc(htmask+1, sizeof(*htable));
+ if (!htable)
+ err(1, "Memory allocation error");
+
+ /* populate newly allocated hashtable */
+ if (ohtable) {
+ int i;
+ for (i = 0; i <= htmask>>1; i++)
+ if (ohtable[i].data)
+ link_check(ohtable[i].data);
+ free(ohtable);
}
}
- if (debug & DEBUG_WALK_DIR_LINKCHECK)
- printf("link_check: no match for [%d, %d]\n",
- entry->st.st_dev, entry->st.st_ino);
- if (ndups == maxdups) {
- if ((newdups = realloc(dups, sizeof(struct dupnode) * (maxdups + 128)))
- == NULL)
- err(1, "Memory allocation error");
- dups = newdups;
- maxdups += 128;
+ /* multiplicative hashing */
+ tmp = entry->st.st_dev;
+ tmp <<= HTBITS>>1;
+ tmp |= entry->st.st_ino;
+ tmp *= HTCONST;
+ h = tmp >> (HTBITS - htshift);
+ h2 = 1 | ( tmp >> (HTBITS - (htshift<<1) - 1)); /* must be odd */
+
+ /* open address hashtable search with double hash probing */
+ while (htable[h].data) {
+ if ((htable[h].data->st.st_ino == entry->st.st_ino) &&
+ (htable[h].data->st.st_dev == entry->st.st_dev)) {
+ return htable[h].data;
+ }
+ h = (h + h2) & htmask;
}
- dups[ndups].dev = entry->st.st_dev;
- dups[ndups].ino = entry->st.st_ino;
- dups[ndups].dup = entry;
- ndups++;
- return (NULL);
+ /* Insert the current entry into hashtable */
+ htable[h].data = entry;
+ htused++;
+ return NULL;
}
diff --git a/usr.sbin/mptutil/mpt_cam.c b/usr.sbin/mptutil/mpt_cam.c
index b14451a..3adbed8 100644
--- a/usr.sbin/mptutil/mpt_cam.c
+++ b/usr.sbin/mptutil/mpt_cam.c
@@ -63,6 +63,7 @@ fetch_path_id(path_id_t *path_id)
struct bus_match_pattern *b;
union ccb ccb;
size_t bufsize;
+ int error;
if (xpt_open() < 0)
return (ENXIO);
@@ -91,9 +92,10 @@ fetch_path_id(path_id_t *path_id)
b->flags = BUS_MATCH_NAME | BUS_MATCH_UNIT | BUS_MATCH_BUS_ID;
if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) {
+ error = errno;
free(ccb.cdm.matches);
free(ccb.cdm.patterns);
- return (errno);
+ return (error);
}
free(ccb.cdm.patterns);
@@ -124,7 +126,7 @@ mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd)
union ccb ccb;
path_id_t path_id;
size_t bufsize;
- int error, i;
+ int error;
/* mpt(4) only handles devices on bus 0. */
if (VolumeBus != 0)
@@ -164,10 +166,10 @@ mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd)
p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME | PERIPH_MATCH_TARGET;
if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) {
- i = errno;
+ error = errno;
free(ccb.cdm.matches);
free(ccb.cdm.patterns);
- return (i);
+ return (error);
}
free(ccb.cdm.patterns);
@@ -397,8 +399,8 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp)
union ccb ccb;
path_id_t path_id;
size_t bufsize;
- u_int i;
int count, error;
+ uint32_t i;
if (xpt_open() < 0)
return (ENXIO);
@@ -431,10 +433,10 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp)
p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME;
if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) {
- i = errno;
+ error = errno;
free(ccb.cdm.matches);
free(ccb.cdm.patterns);
- return (i);
+ return (error);
}
free(ccb.cdm.patterns);
@@ -481,6 +483,8 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp)
* exclude them from the list.
*/
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
+ if (ioc2 == NULL)
+ return (errno);
disks = calloc(ccb.cdm.num_matches, sizeof(*disks));
count = 0;
for (i = 0; i < ccb.cdm.num_matches; i++) {
diff --git a/usr.sbin/mptutil/mpt_cmd.c b/usr.sbin/mptutil/mpt_cmd.c
index 2d6000c..8104fc9 100644
--- a/usr.sbin/mptutil/mpt_cmd.c
+++ b/usr.sbin/mptutil/mpt_cmd.c
@@ -310,18 +310,15 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID)
id = strtol(cp + 1, &cp, 0);
if (*cp == '\0') {
if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
- errno = EINVAL;
- return (-1);
+ return (EINVAL);
}
*VolumeBus = bus;
*VolumeID = id;
return (0);
}
} else if (*cp == '\0') {
- if (bus < 0 || bus > 0xff) {
- errno = EINVAL;
- return (-1);
- }
+ if (bus < 0 || bus > 0xff)
+ return (EINVAL);
*VolumeBus = 0;
*VolumeID = bus;
return (0);
@@ -329,7 +326,7 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID)
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (ioc2 == NULL)
- return (-1);
+ return (errno);
vol = ioc2->RaidVolume;
for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
@@ -343,8 +340,7 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID)
}
}
free(ioc2);
- errno = EINVAL;
- return (-1);
+ return (EINVAL);
}
int
@@ -360,15 +356,14 @@ mpt_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
req.header.PageNumber = PageNumber;
req.page_address = PageAddress;
if (ioctl(fd, MPTIO_READ_CFG_HEADER, &req) < 0)
- return (-1);
+ return (errno);
if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
if (IOCStatus != NULL)
*IOCStatus = req.ioc_status;
else
warnx("Reading config page header failed: %s",
mpt_ioc_status(req.ioc_status));
- errno = EIO;
- return (-1);
+ return (EIO);
}
*header = req.header;
return (0);
@@ -380,7 +375,7 @@ mpt_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
{
struct mpt_cfg_page_req req;
void *buf;
- int save_errno;
+ int error;
if (IOCStatus != NULL)
*IOCStatus = MPI_IOCSTATUS_SUCCESS;
@@ -404,9 +399,9 @@ mpt_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
req.buf = buf;
bcopy(&req.header, buf, sizeof(req.header));
if (ioctl(fd, MPTIO_READ_CFG_PAGE, &req) < 0) {
- save_errno = errno;
+ error = errno;
free(buf);
- errno = save_errno;
+ errno = error;
return (NULL);
}
if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
@@ -428,7 +423,7 @@ mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
{
struct mpt_ext_cfg_page_req req;
void *buf;
- int save_errno;
+ int error;
if (IOCStatus != NULL)
*IOCStatus = MPI_IOCSTATUS_SUCCESS;
@@ -453,9 +448,9 @@ mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
req.buf = buf;
bcopy(&req.header, buf, sizeof(req.header));
if (ioctl(fd, MPTIO_READ_EXT_CFG_PAGE, &req) < 0) {
- save_errno = errno;
+ error = errno;
free(buf);
- errno = save_errno;
+ errno = error;
return (NULL);
}
if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
@@ -484,7 +479,7 @@ mpt_write_config_page(int fd, void *buf, U16 *IOCStatus)
hdr = buf;
req.len = hdr->PageLength * 4;
if (ioctl(fd, MPTIO_WRITE_CFG_PAGE, &req) < 0)
- return (-1);
+ return (errno);
if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
if (IOCStatus != NULL) {
*IOCStatus = req.ioc_status;
@@ -492,8 +487,7 @@ mpt_write_config_page(int fd, void *buf, U16 *IOCStatus)
}
warnx("Writing config page failed: %s",
mpt_ioc_status(req.ioc_status));
- errno = EIO;
- return (-1);
+ return (EIO);
}
return (0);
}
@@ -507,10 +501,8 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum,
if (IOCStatus != NULL)
*IOCStatus = MPI_IOCSTATUS_SUCCESS;
- if (datalen < 0 || (unsigned)datalen > sizeof(raid_act.action_data)) {
- errno = EINVAL;
- return (-1);
- }
+ if (datalen < 0 || (unsigned)datalen > sizeof(raid_act.action_data))
+ return (EINVAL);
bzero(&raid_act, sizeof(raid_act));
raid_act.action = Action;
raid_act.volume_bus = VolumeBus;
@@ -524,7 +516,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum,
}
if (ioctl(fd, MPTIO_RAID_ACTION, &raid_act) < 0)
- return (-1);
+ return (errno);
if (!IOC_STATUS_SUCCESS(raid_act.ioc_status)) {
if (IOCStatus != NULL) {
@@ -533,8 +525,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum,
}
warnx("RAID action failed: %s",
mpt_ioc_status(raid_act.ioc_status));
- errno = EIO;
- return (-1);
+ return (EIO);
}
if (ActionStatus != NULL)
@@ -544,8 +535,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum,
return (0);
warnx("RAID action failed: %s",
mpt_raid_status(raid_act.action_status));
- errno = EIO;
- return (-1);
+ return (EIO);
}
if (VolumeStatus != NULL)
diff --git a/usr.sbin/mptutil/mpt_config.c b/usr.sbin/mptutil/mpt_config.c
index 3874df3..6247bb4 100644
--- a/usr.sbin/mptutil/mpt_config.c
+++ b/usr.sbin/mptutil/mpt_config.c
@@ -102,15 +102,15 @@ mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
*/
return (0);
if (error) {
- errno = error;
- warn("Unable to lookup volume device name");
- return (-1);
+ warnc(error, "Unable to lookup volume device name");
+ return (error);
}
snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
vfd = open(path, O_RDWR);
if (vfd < 0) {
+ error = errno;
warn("Unable to lock volume %s", qd.devname);
- return (-1);
+ return (error);
}
return (0);
}
@@ -119,13 +119,14 @@ static int
mpt_lock_physdisk(struct mpt_standalone_disk *disk)
{
char path[MAXPATHLEN];
- int dfd;
+ int dfd, error;
snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
dfd = open(path, O_RDWR);
if (dfd < 0) {
+ error = errno;
warn("Unable to lock disk %s", disk->devname);
- return (-1);
+ return (error);
}
return (0);
}
@@ -144,8 +145,7 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
id = strtol(cp + 1, &cp, 0);
if (*cp == '\0') {
if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
- errno = EINVAL;
- return (-1);
+ return (EINVAL);
}
for (i = 0; i < ndisks; i++) {
if (disks[i].bus == (U8)bus &&
@@ -154,8 +154,7 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
return (0);
}
}
- errno = ENOENT;
- return (-1);
+ return (ENOENT);
}
}
@@ -166,12 +165,10 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
return (0);
}
}
- errno = ENOENT;
- return (-1);
+ return (ENOENT);
}
- errno = EINVAL;
- return (-1);
+ return (EINVAL);
}
/*
@@ -182,16 +179,17 @@ mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
{
CONFIG_PAGE_HEADER header;
CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
+ int error;
U32 ActionData;
- if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
- 0, 0, &header, NULL) < 0)
- return (-1);
+ error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
+ 0, 0, &header, NULL);
+ if (error)
+ return (error);
if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
warnx("Unsupported RAID physdisk page 0 version %d",
header.PageVersion);
- errno = EOPNOTSUPP;
- return (-1);
+ return (EOPNOTSUPP);
}
config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
@@ -203,10 +201,11 @@ mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
config_page->PhysDiskID = disk->target;
/* XXX: Enclosure info for PhysDiskSettings? */
- if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
- &ActionData, sizeof(ActionData), NULL, NULL, 1) < 0)
- return (-1);
+ &ActionData, sizeof(ActionData), NULL, NULL, 1);
+ if (error)
+ return (error);
*PhysDiskNum = ActionData & 0xff;
return (0);
}
@@ -232,18 +231,20 @@ clear_config(int ac, char **av)
IOC_3_PHYS_DISK *disk;
CONFIG_PAGE_IOC_5 *ioc5;
IOC_5_HOT_SPARE *spare;
- int ch, fd, i;
+ int ch, error, fd, i;
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (ioc2 == NULL) {
+ error = errno;
warn("Failed to fetch volume list");
- return (errno);
+ return (error);
}
/* Lock all the volumes first. */
@@ -267,14 +268,16 @@ clear_config(int ac, char **av)
/* Delete all the volumes. */
vol = ioc2->RaidVolume;
- for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++)
- if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
+ for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
vol->VolumeBus, vol->VolumeID, 0,
MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
- NULL, NULL, 0) < 0)
- warn("Failed to delete volume %s",
+ NULL, NULL, 0);
+ if (error)
+ warnc(error, "Failed to delete volume %s",
mpt_volume_name(vol->VolumeBus, vol->VolumeID));
+ }
free(ioc2);
/* Delete all the spares. */
@@ -411,8 +414,9 @@ parse_volume(int fd, int raid_type, struct config_id_state *state,
/* See if it is a standalone disk. */
if (mpt_lookup_standalone_disk(cp, state->sdisks,
state->nsdisks, &i) < 0) {
+ error = errno;
warn("Unable to lookup drive %s", cp);
- return (errno);
+ return (error);
}
dinfo->sdisk = &state->sdisks[i];
@@ -433,17 +437,18 @@ add_drives(int fd, struct volume_info *info, int verbose)
{
struct drive_info *dinfo;
U8 PhysDiskNum;
- int i;
+ int error, i;
for (i = 0, dinfo = info->drives; i < info->drive_count;
i++, dinfo++) {
if (dinfo->info == NULL) {
if (mpt_create_physdisk(fd, dinfo->sdisk,
&PhysDiskNum) < 0) {
+ error = errno;
warn(
"Failed to create physical disk page for %s",
dinfo->sdisk->devname);
- return (errno);
+ return (error);
}
if (verbose)
printf("Added drive %s with PhysDiskNum %u\n",
@@ -500,11 +505,14 @@ build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
U32 MinLBA;
uint64_t MaxLBA;
size_t page_size;
- int i;
+ int error, i;
- if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
- 0, 0, &header, NULL) < 0)
+ error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
+ 0, 0, &header, NULL);
+ if (error) {
+ errno = error;
return (NULL);
+ }
if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
warnx("Unsupported RAID volume page 0 version %d",
header.PageVersion);
@@ -514,6 +522,8 @@ build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
vol = calloc(1, page_size);
+ if (vol == NULL)
+ return (NULL);
/* Header */
vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
@@ -607,8 +617,8 @@ create_volume(int ac, char **av)
CONFIG_PAGE_RAID_VOL_0 *vol;
struct config_id_state state;
struct volume_info *info;
- int ch, error, fd, i, raid_type, verbose, quick;
long stripe_size;
+ int ch, error, fd, i, quick, raid_type, verbose;
#ifdef DEBUG
int dump;
#endif
@@ -620,8 +630,9 @@ create_volume(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
/* Lookup the RAID type first. */
@@ -677,8 +688,9 @@ create_volume(int ac, char **av)
/* Fetch existing config data. */
state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (state.ioc2 == NULL) {
+ error = errno;
warn("Failed to read volume list");
- return (errno);
+ return (error);
}
state.list = mpt_pd_list(fd);
if (state.list == NULL)
@@ -696,6 +708,8 @@ create_volume(int ac, char **av)
return (EINVAL);
}
info = calloc(1, sizeof(*info));
+ if (info == NULL)
+ return (ENOMEM);
error = parse_volume(fd, raid_type, &state, av[0], info);
if (error)
return (error);
@@ -707,6 +721,8 @@ create_volume(int ac, char **av)
/* Build the volume. */
vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
+ if (vol == NULL)
+ return (errno);
#ifdef DEBUG
if (dump) {
@@ -716,12 +732,13 @@ create_volume(int ac, char **av)
#endif
/* Send the new volume to the controller. */
- if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
- vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1) <
- 0) {
+ vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
+ if (error) {
+ errno = error;
warn("Failed to add volume");
- return (errno);
+ return (error);
}
#ifdef DEBUG
@@ -745,7 +762,7 @@ static int
delete_volume(int ac, char **av)
{
U8 VolumeBus, VolumeID;
- int fd;
+ int error, fd;
if (ac != 2) {
warnx("delete: volume required");
@@ -754,24 +771,27 @@ delete_volume(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
- if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume %s", av[1]);
- return (errno);
+ error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume %s", av[1]);
+ return (error);
}
if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
return (errno);
- if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
- NULL, 0) < 0) {
- warn("Failed to delete volume");
- return (errno);
+ NULL, 0);
+ if (error) {
+ warnc(error, "Failed to delete volume");
+ return (error);
}
mpt_rescan_bus(-1, -1);
@@ -788,16 +808,17 @@ find_volume_spare_pool(int fd, const char *name, int *pool)
CONFIG_PAGE_IOC_2 *ioc2;
CONFIG_PAGE_IOC_2_RAID_VOL *vol;
U8 VolumeBus, VolumeID;
- int i, j, new_pool, pool_count[7];
+ int error, i, j, new_pool, pool_count[7];
- if (mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume %s", name);
- return (-1);
+ error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume %s", name);
+ return (error);
}
info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
if (info == NULL)
- return (-1);
+ return (errno);
/*
* Check for an existing pool other than pool 0 (used for
@@ -817,15 +838,16 @@ find_volume_spare_pool(int fd, const char *name, int *pool)
*/
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (ioc2 == NULL) {
+ error = errno;
warn("Failed to fetch volume list");
- return (-1);
+ return (error);
}
bzero(pool_count, sizeof(pool_count));
vol = ioc2->RaidVolume;
for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
if (info == NULL)
- return (-1);
+ return (errno);
for (j = 0; j < 7; j++)
if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
pool_count[j]++;
@@ -843,14 +865,15 @@ find_volume_spare_pool(int fd, const char *name, int *pool)
/* Add this pool to the volume. */
info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
if (info == NULL)
- return (-1);
+ return (error);
info->VolumeSettings.HotSparePool |= (1 << new_pool);
- if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
- NULL, NULL, 0, NULL, NULL, 0) < 0) {
+ NULL, NULL, 0, NULL, NULL, 0);
+ if (error) {
warnx("Failed to add spare pool %d to %s", new_pool,
mpt_volume_name(VolumeBus, VolumeID));
- return (-1);
+ return (error);
}
free(info);
@@ -878,13 +901,15 @@ add_spare(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
if (ac == 3) {
- if (find_volume_spare_pool(fd, av[2], &pool) < 0)
- return (errno);
+ error = find_volume_spare_pool(fd, av[2], &pool);
+ if (error)
+ return (error);
} else
pool = MPI_RAID_HOT_SPARE_POOL_0;
@@ -902,16 +927,18 @@ add_spare(int ac, char **av)
if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
0) {
+ error = errno;
warn("Unable to lookup drive %s", av[1]);
- return (errno);
+ return (error);
}
if (mpt_lock_physdisk(&sdisks[i]) < 0)
return (errno);
if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to create physical disk page");
- return (errno);
+ return (error);
}
free(sdisks);
}
@@ -919,8 +946,9 @@ add_spare(int ac, char **av)
info = mpt_pd_info(fd, PhysDiskNum, NULL);
if (info == NULL) {
+ error = errno;
warn("Failed to fetch drive info");
- return (errno);
+ return (error);
}
info->PhysDiskSettings.HotSparePool = pool;
@@ -928,8 +956,8 @@ add_spare(int ac, char **av)
0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
NULL, 0, NULL, NULL, 0);
if (error) {
- warn("Failed to assign spare");
- return (errno);
+ warnc(error, "Failed to assign spare");
+ return (error);
}
free(info);
@@ -954,8 +982,9 @@ remove_spare(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
list = mpt_pd_list(fd);
@@ -972,8 +1001,9 @@ remove_spare(int ac, char **av)
info = mpt_pd_info(fd, PhysDiskNum, NULL);
if (info == NULL) {
+ error = errno;
warn("Failed to fetch drive info");
- return (errno);
+ return (error);
}
if (info->PhysDiskSettings.HotSparePool == 0) {
@@ -982,8 +1012,9 @@ remove_spare(int ac, char **av)
}
if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to delete physical disk page");
- return (errno);
+ return (error);
}
mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
@@ -1011,8 +1042,9 @@ pd_create(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
error = mpt_fetch_disks(fd, &ndisks, &disks);
@@ -1022,16 +1054,18 @@ pd_create(int ac, char **av)
}
if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
+ error = errno;
warn("Unable to lookup drive");
- return (errno);
+ return (error);
}
if (mpt_lock_physdisk(&disks[i]) < 0)
return (errno);
if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to create physical disk page");
- return (errno);
+ return (error);
}
free(disks);
@@ -1048,7 +1082,7 @@ pd_delete(int ac, char **av)
{
CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
struct mpt_drive_list *list;
- int fd;
+ int error, fd;
U8 PhysDiskNum;
if (ac != 2) {
@@ -1058,8 +1092,9 @@ pd_delete(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
list = mpt_pd_list(fd);
@@ -1067,20 +1102,23 @@ pd_delete(int ac, char **av)
return (errno);
if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to find drive %s", av[1]);
- return (errno);
+ return (error);
}
mpt_free_pd_list(list);
info = mpt_pd_info(fd, PhysDiskNum, NULL);
if (info == NULL) {
+ error = errno;
warn("Failed to fetch drive info");
- return (errno);
+ return (error);
}
if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to delete physical disk page");
- return (errno);
+ return (error);
}
mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
@@ -1126,7 +1164,7 @@ debug_config(int ac, char **av)
{
CONFIG_PAGE_RAID_VOL_0 *vol;
U8 VolumeBus, VolumeID;
- int fd;
+ int error, fd;
if (ac != 2) {
warnx("debug: volume required");
@@ -1135,19 +1173,22 @@ debug_config(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
- if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume: %s", av[1]);
- return (errno);
+ error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume: %s", av[1]);
+ return (error);
}
vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
if (vol == NULL) {
+ error = errno;
warn("Failed to get volume info");
- return (errno);
+ return (error);
}
dump_config(vol);
diff --git a/usr.sbin/mptutil/mpt_drive.c b/usr.sbin/mptutil/mpt_drive.c
index e941b96..049ce71 100644
--- a/usr.sbin/mptutil/mpt_drive.c
+++ b/usr.sbin/mptutil/mpt_drive.c
@@ -129,7 +129,7 @@ mpt_pd_insert(int fd, struct mpt_drive_list *list, U8 PhysDiskNum)
list->drives[j + 1] = list->drives[j];
list->drives[i] = mpt_pd_info(fd, PhysDiskNum, NULL);
if (list->drives[i] == NULL)
- return (-1);
+ return (errno);
list->ndrives++;
return (0);
}
@@ -146,26 +146,32 @@ mpt_pd_list(int fd)
CONFIG_PAGE_IOC_5 *ioc5;
IOC_5_HOT_SPARE *spare;
struct mpt_drive_list *list;
- int count, i, j;
+ int count, error, i, j;
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (ioc2 == NULL) {
+ error = errno;
warn("Failed to fetch volume list");
+ errno = error;
return (NULL);
}
ioc3 = mpt_read_ioc_page(fd, 3, NULL);
if (ioc3 == NULL) {
+ error = errno;
warn("Failed to fetch drive list");
free(ioc2);
+ errno = error;
return (NULL);
}
ioc5 = mpt_read_ioc_page(fd, 5, NULL);
if (ioc5 == NULL) {
+ error = errno;
warn("Failed to fetch spare list");
free(ioc3);
free(ioc2);
+ errno = error;
return (NULL);
}
@@ -180,7 +186,9 @@ mpt_pd_list(int fd)
volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
NULL);
if (volumes[i] == NULL) {
+ error = errno;
warn("Failed to read volume info");
+ errno = error;
return (NULL);
}
count += volumes[i]->NumPhysDisks;
@@ -264,13 +272,11 @@ mpt_lookup_drive(struct mpt_drive_list *list, const char *drive,
return (0);
}
}
- errno = ENOENT;
- return (-1);
+ return (ENOENT);
}
bad:
- errno = EINVAL;
- return (-1);
+ return (EINVAL);
}
/* Borrowed heavily from scsi_all.c:scsi_print_inquiry(). */
@@ -306,12 +312,13 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name)
CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
struct mpt_drive_list *list;
U8 PhysDiskNum;
- int fd;
+ int error, fd;
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
list = mpt_pd_list(fd);
@@ -319,16 +326,18 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name)
return (errno);
if (mpt_lookup_drive(list, drive, &PhysDiskNum) < 0) {
+ error = errno;
warn("Failed to find drive %s", drive);
- return (errno);
+ return (error);
}
mpt_free_pd_list(list);
/* Get the info for this drive. */
info = mpt_pd_info(fd, PhysDiskNum, NULL);
if (info == NULL) {
+ error = errno;
warn("Failed to fetch info for drive %u", PhysDiskNum);
- return (errno);
+ return (error);
}
/* Try to change the state. */
@@ -337,10 +346,11 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name)
return (EINVAL);
}
- if (mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL,
- NULL, 0, NULL, NULL, 0) < 0) {
- warn("Failed to set drive %u to %s", PhysDiskNum, name);
- return (errno);
+ error = mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL,
+ NULL, 0, NULL, NULL, 0);
+ if (error) {
+ warnc(error, "Failed to set drive %u to %s", PhysDiskNum, name);
+ return (error);
}
free(info);
diff --git a/usr.sbin/mptutil/mpt_evt.c b/usr.sbin/mptutil/mpt_evt.c
index 4b64352..9ccdebd 100644
--- a/usr.sbin/mptutil/mpt_evt.c
+++ b/usr.sbin/mptutil/mpt_evt.c
@@ -94,18 +94,20 @@ show_events(int ac, char **av)
{
CONFIG_PAGE_LOG_0 *log;
MPI_LOG_0_ENTRY **entries;
- int ch, fd, i, num_events, verbose;
+ int ch, error, fd, i, num_events, verbose;
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
log = mpt_get_events(fd, NULL);
if (log == NULL) {
+ error = errno;
warn("Failed to get event log info");
- return (errno);
+ return (error);
}
/* Default settings. */
@@ -128,6 +130,8 @@ show_events(int ac, char **av)
/* Build a list of valid entries and sort them by sequence. */
entries = malloc(sizeof(MPI_LOG_0_ENTRY *) * log->NumLogEntries);
+ if (entries == NULL)
+ return (ENOMEM);
num_events = 0;
for (i = 0; i < log->NumLogEntries; i++) {
if (log->LogEntry[i].LogEntryQualifier ==
diff --git a/usr.sbin/mptutil/mpt_show.c b/usr.sbin/mptutil/mpt_show.c
index 5a2a946..a5e1a89 100644
--- a/usr.sbin/mptutil/mpt_show.c
+++ b/usr.sbin/mptutil/mpt_show.c
@@ -79,7 +79,7 @@ show_adapter(int ac, char **av)
CONFIG_PAGE_IOC_2 *ioc2;
CONFIG_PAGE_IOC_6 *ioc6;
U16 IOCStatus;
- int fd, comma;
+ int comma, error, fd;
if (ac != 1) {
warnx("show adapter: extra arguments");
@@ -88,17 +88,19 @@ show_adapter(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
man0 = mpt_read_man_page(fd, 0, NULL);
if (man0 == NULL) {
+ error = errno;
warn("Failed to get controller info");
- return (errno);
+ return (error);
}
if (man0->Header.PageLength < sizeof(*man0) / 4) {
- warn("Invalid controller info");
+ warnx("Invalid controller info");
return (EINVAL);
}
printf("mpt%d Adapter:\n", mpt_unit);
@@ -283,7 +285,7 @@ show_config(int ac, char **av)
CONFIG_PAGE_RAID_VOL_1 *vnames;
CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
struct mpt_standalone_disk *sdisks;
- int fd, i, j, nsdisks;
+ int error, fd, i, j, nsdisks;
if (ac != 1) {
warnx("show config: extra arguments");
@@ -292,20 +294,23 @@ show_config(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
/* Get the config from the controller. */
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
ioc5 = mpt_read_ioc_page(fd, 5, NULL);
if (ioc2 == NULL || ioc5 == NULL) {
+ error = errno;
warn("Failed to get config");
- return (errno);
+ return (error);
}
if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
+ error = errno;
warn("Failed to get standalone drive list");
- return (errno);
+ return (error);
}
/* Dump out the configuration. */
@@ -381,7 +386,7 @@ show_volumes(int ac, char **av)
CONFIG_PAGE_IOC_2_RAID_VOL *vol;
CONFIG_PAGE_RAID_VOL_0 **volumes;
CONFIG_PAGE_RAID_VOL_1 *vnames;
- int fd, i, len, state_len;
+ int error, fd, i, len, state_len;
if (ac != 1) {
warnx("show volumes: extra arguments");
@@ -390,15 +395,17 @@ show_volumes(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
/* Get the volume list from the controller. */
ioc2 = mpt_read_ioc_page(fd, 2, NULL);
if (ioc2 == NULL) {
+ error = errno;
warn("Failed to get volume list");
- return (errno);
+ return (error);
}
/*
@@ -466,7 +473,7 @@ show_drives(int ac, char **av)
{
struct mpt_drive_list *list;
struct mpt_standalone_disk *sdisks;
- int fd, i, len, nsdisks, state_len;
+ int error, fd, i, len, nsdisks, state_len;
if (ac != 1) {
warnx("show drives: extra arguments");
@@ -475,15 +482,17 @@ show_drives(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
/* Get the drive list. */
list = mpt_pd_list(fd);
if (list == NULL) {
+ error = errno;
warn("Failed to get drive list");
- return (errno);
+ return (error);
}
/* Fetch the list of standalone disks for this controller. */
@@ -538,8 +547,9 @@ show_physdisks(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
/* Try to find each possible phys disk page. */
diff --git a/usr.sbin/mptutil/mpt_volume.c b/usr.sbin/mptutil/mpt_volume.c
index 04adcb7..2b273c7 100644
--- a/usr.sbin/mptutil/mpt_volume.c
+++ b/usr.sbin/mptutil/mpt_volume.c
@@ -69,7 +69,7 @@ volume_name(int ac, char **av)
{
CONFIG_PAGE_RAID_VOL_1 *vnames;
U8 VolumeBus, VolumeID;
- int fd;
+ int error, fd;
if (ac != 3) {
warnx("name: volume and name required");
@@ -83,19 +83,22 @@ volume_name(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
- if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume: %s", av[1]);
- return (errno);
+ error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume: %s", av[1]);
+ return (error);
}
vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL);
if (vnames == NULL) {
+ error = errno;
warn("Failed to fetch volume names");
- return (errno);
+ return (error);
}
if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) {
@@ -109,8 +112,9 @@ volume_name(int ac, char **av)
strcpy(vnames->Name, av[2]);
if (mpt_write_config_page(fd, vnames, NULL) < 0) {
+ error = errno;
warn("Failed to set volume name");
- return (errno);
+ return (error);
}
free(vnames);
@@ -128,7 +132,7 @@ volume_status(int ac, char **av)
uint64_t total, remaining;
float pct;
U8 VolumeBus, VolumeID;
- int fd;
+ int error, fd;
if (ac != 2) {
warnx("volume status: %s", ac > 2 ? "extra arguments" :
@@ -138,20 +142,23 @@ volume_status(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
- if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume: %s", av[1]);
- return (errno);
+ error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume: %s", av[1]);
+ return (error);
}
- if (mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus,
VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog),
- NULL, NULL, 0) < 0) {
- warn("Fetching volume status failed");
- return (errno);
+ NULL, NULL, 0);
+ if (error) {
+ warnc(error, "Fetching volume status failed");
+ return (error);
}
printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID));
@@ -191,11 +198,11 @@ volume_cache(int ac, char **av)
U32 Settings, NewSettings;
U8 VolumeBus, VolumeID;
char *s1;
- int fd;
+ int error, fd;
if (ac != 3) {
warnx("volume cache: %s", ac > 3 ? "extra arguments" :
- "volume required");
+ "missing arguments");
return (EINVAL);
}
@@ -209,18 +216,20 @@ volume_cache(int ac, char **av)
fd = mpt_open(mpt_unit);
if (fd < 0) {
+ error = errno;
warn("mpt_open");
- return (errno);
+ return (error);
}
- if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
- warn("Invalid volume: %s", av[1]);
- return (errno);
+ error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
+ if (error) {
+ warnc(error, "Invalid volume: %s", av[1]);
+ return (error);
}
volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
if (volume == NULL)
- return (-1);
+ return (errno);
Settings = volume->VolumeSettings.Settings;
@@ -231,18 +240,19 @@ volume_cache(int ac, char **av)
NewSettings &= ~0x01;
if (NewSettings == Settings) {
- warnx("volume cache unchanged\n");
+ warnx("volume cache unchanged");
close(fd);
return (0);
}
volume->VolumeSettings.Settings = NewSettings;
- if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
+ error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0,
- NULL, NULL, 0, NULL, NULL, 0) < 0)
- warnx("volume cache change failed, errno= %d\n", errno);
+ NULL, NULL, 0, NULL, NULL, 0);
+ if (error)
+ warnc(error, "volume cache change failed");
close(fd);
- return (0);
+ return (error);
}
MPT_COMMAND(volume, cache, volume_cache);
diff --git a/usr.sbin/pc-sysinstall/backend/functions-disk.sh b/usr.sbin/pc-sysinstall/backend/functions-disk.sh
index c6e849c..0b14591 100755
--- a/usr.sbin/pc-sysinstall/backend/functions-disk.sh
+++ b/usr.sbin/pc-sysinstall/backend/functions-disk.sh
@@ -646,8 +646,11 @@ init_mbr_full_disk()
rc_halt "dd if=/dev/zero of=/dev/${_intDISK}s1 count=1024"
if [ "$_intBOOT" = "bsd" ] ; then
- echo_log "Stamping boot sector on ${_intDISK}"
+ echo_log "Stamping boot0 on ${_intDISK}"
rc_halt "gpart bootcode -b /boot/boot0 ${_intDISK}"
+ else
+ echo_log "Stamping boot1 on ${_intDISK}"
+ rc_halt "gpart bootcode -b /boot/boot1 ${_intDISK}"
fi
}
diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8
index 971367d..ae69737 100644
--- a/usr.sbin/usbconfig/usbconfig.8
+++ b/usr.sbin/usbconfig/usbconfig.8
@@ -92,5 +92,9 @@ Display a list of available quirk names:
.Pp
.Dl usbconfig dump_quirk_names
.Pp
+See
+.Xr usb_quirk 4
+for more information on quirks.
.Sh SEE ALSO
-.Xr usb 4
+.Xr usb 4 ,
+.Xr usb_quirk 4
OpenPOWER on IntegriCloud